Yanıt: {"current_time":1743008807,"status":200,"response_code":1000,"data":{"bookings":[]}} ben burada 3sn de bir apiye istek göndererek bookings içinde yeni sipariş geldiğinde id numarasını almam gerekli. ve aldıktan sonra request ile https://siteadi.com/(id) ye gitmeli bunu nasıl yapabilirim yardımcı olabilecek varmı
python ücretsiz yardım edebilecek varmı
4
●154
- 26-03-2025, 20:12:02Üyeliği durdurulduBir api var ve apiye bu şekilde bağlanabiliyorum ve bağlandığımda sonuç
- 26-03-2025, 20:20:14import requests
import time
# API URL'si
api_url = "https://api.example.com/endpoint"
site_url = "https://siteadi.com/"
while True:
try:
response = requests.get(api_url)
data = response.json()
if response.status_code == 200 and data.get('response_code') == 1000:
# bookings içinde yeni sipariş varsa
if data['data']['bookings']:
# İlk siparişi al
booking_id = data['data']['bookings'][0]['id']
booking_url = site_url + str(booking_id)
print(f"Yeni sipariş bulundu! Yönlendirilmekte: {booking_url}")
# request_response = requests.get(booking_url)
# print(request_response.status_code)
break
else:
print("Veri çekilemedi veya başka bir hata oluştu.")
except Exception as e:
print(f"Bir hata oluştu: {e}")
time.sleep(3) - 11-04-2025, 21:56:05cursor >>
import requests import time import json def check_bookings(): # Session oluşturma session = requests.session() # Önceki siparişlerin ID'lerini tutmak için liste mevcut_booking_idler = [] while True: try: # API'ye istek gönderme yanit = session.get("https://siteadi.com/api/endpoint") # API URL'sini buraya yazın # API yanıtını JSON olarak ayrıştırma yanit_json = yanit.json() # API yanıtı kontrolü if yanit_json["status"] == 200 and yanit_json["response_code"] == 1000: # Bookings listesini alma bookings = yanit_json["data"]["bookings"] # Tüm bookings'leri kontrol etme for booking in bookings: booking_id = booking.get("id") # ID'yi alma # Eğer bu ID daha önce işlenmediyse if booking_id and booking_id not in mevcut_booking_idler: print(f"Yeni sipariş bulundu! ID: {booking_id}") # ID'yi işlenmiş olarak kaydetme mevcut_booking_idler.append(booking_id) # ID ile yeni URL'ye istek gönderme siparis_url = f"https://siteadi.com/{booking_id}" siparis_yanit = session.get(siparis_url) print(f"Sipariş URL'sine istek gönderildi: {siparis_url}") print(f"Yanıt: {siparis_yanit.text[:100]}...") # Yanıtın ilk 100 karakterini göster else: print(f"API hatası: {yanit_json}") except Exception as e: print(f"Hata oluştu: {e}") # 3 saniye bekleme time.sleep(3) if __name__ == "__main__": print("Sipariş takip sistemi başlatılıyor...") check_bookings() """ API Sipariş Takip Sistemi Geliştirme Notları ------------------------------------- 1. Geliştirilen Özellikler: - requests.session kullanarak API bağlantısı - 3 saniye aralıklarla periyodik olarak API kontrolü - Yeni siparişlerin tespit edilmesi - Tespit edilen siparişlerin ID'lerinin kaydedilmesi - Sipariş ID'leri ile ikincil API isteklerinin yapılması 2. Kullanılan Kütüphaneler: - requests: HTTP istekleri için - time: Periyodik istekler için bekleme süresi - json: API yanıtlarının işlenmesi için 3. Çalışma Mantığı: - Sistem, belirtilen API endpoint'ine 3 saniyede bir istek gönderir - API yanıtındaki "bookings" dizisini kontrol eder - Daha önce işlenmemiş sipariş ID'lerini tespit eder - Yeni ID bulunduğunda "https://siteadi.com/{id}" adresine istek gönderir 4. Geliştirme Notları: - Hata yönetimi için try-except blokları kullanıldı - Önceki siparişlerin tekrar işlenmesini engellemek için ID listesi tutuldu - API yanıtının başarılı olup olmadığını kontrol etmek için status ve response_code kullanıldı """