import pymysql
import time
connection = None
def get_veri():
global connection
try:
# Bağlantıyı kontrol et ve gerekirse yeniden bağlan
if connection is None or not connection.open:
connection = pymysql.connect(host="192.242.117.123",
user="ss",
password="hD5e27xy",
database="ss")
print("Bağlantı başarıyla kuruldu.")
cursor = connection.cursor()
# Veritabanından veri çek
cursor.execute("SELECT * FROM keklik")
results = cursor.fetchall()
if not results:
print("Veritabanında yeni veri bulunamadı.")
return None
else:
for row in results:
isim = row[0]
sehir = row[1]
print(f"İsim: {isim}, Şehir: {sehir}")
# En son çekilen kaydı takip etmek için son kaydın ID'sini güncelleyebilirsiniz
# last_id = results[-1][0] # ID sütunu ilk sütunsa ve sonuçlar ters sıralıysa
except Exception as e:
print(f"Bir hata oluştu: {e}")
return None
# Sürekli döngü içinde veri çek
while True:
get_veri()
time.sleep(10) # 10 saniye beklet
chat gpt ile güncellettim hocam.