Merhaba, bazı işaretçiler Python'da sorun oluşturabiliyor. Bir de şu kodu dener misin?
import csv
import requests
import time
BOT_TOKEN = "TOKEN"
CHAT_ID = "-GRUP CHAT ID"
TEMP_MIN = 20.0
TEMP_MAX = 25.9
HUMIDITY_MIN = 40
HUMIDITY_MAX = 60
def send_telegram_message(message):
url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage"
data = {"chat_id": CHAT_ID, "text": message}
try:
response = requests.post(url, data=data)
if response.status_code == 200:
print("Telegram bildirimi gönderildi.")
else:
print(f"Telegram bildirimi gönderilemedi. Hata kodu: {response.status_code}")
except Exception as e:
print(f"Telegram gönderim hatası: {e}")
def process_data(file_path, notified_entries):
try:
with open(file_path, "r", encoding="utf-8") as file:
reader = csv.reader(file, delimiter=";", quotechar='"')
next(reader) # Başlık satırını atla
for row in reader:
if len(row) < 3:
continue
date = row[0].strip('"')
indoor_temp = row[1].strip('"')
indoor_humidity = row[2].strip('"')
if indoor_temp == "---" or indoor_humidity == "---":
continue
try:
temp = float(indoor_temp)
humidity = float(indoor_humidity)
if temp < TEMP_MIN or temp > TEMP_MAX or humidity < HUMIDITY_MIN or humidity > HUMIDITY_MAX:
unique_key = f"{date}_{temp}_{humidity}"
if unique_key not in notified_entries:
message = (f"Dikkat! {date} tarihinde ölçülen değerler referans aralığın dışında:\n"
f"Sıcaklık: {temp}°C (Aralık: {TEMP_MIN}-{TEMP_MAX}°C)\n"
f"Nem: {humidity}% (Aralık: {HUMIDITY_MIN}-{HUMIDITY_MAX}%)")
send_telegram_message(message)
notified_entries.add(unique_key)
except ValueError as e:
print(f"Veri dönüştürme hatası: {indoor_temp}, {indoor_humidity}, Hata: {e}")
except FileNotFoundError:
print(f"Hata: {file_path} dosyası bulunamadı!")
except Exception as e:
print(f"Dosya işleme hatası: {e}")
if __name__ == "__main__":
file_path = r"C:\Konum\data.txt"
notified_entries = set()
print("Sistem çalışmaya başladı. Veriler yarım saatte bir kontrol ediliyor...")
while True:
process_data(file_path, notified_entries)
time.sleep(1800)
Cevabınız için teşekkür ederim fakat yine bir mesaj almadım. Datalogger işaretçileriyle ilgili mi bir sorun var anlayamadım