import requests
from bs4 import BeautifulSoup
import time
# Telegram API url and token
TELEGRAM_URL = "https://api.telegram.org/bot"
TOKEN = "XXXXXXXXXXX"
# User-agent
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36'}
# Initialize the previous_price variable
previous_price = 0
def send_message(message, chat_id = "-XXXXXXX"):
url = f"{TELEGRAM_URL}{TOKEN}/sendMessage?chat_id={chat_id}&text={message}"
requests.get(url)
# Open the file containing URLs
with open("urls.txt", "r") as file:
# Read the file and store the URLs in a list
urls = file.readlines()
while True:
# Iterate through the list of URLs
for url in urls:
# Use requests to get the HTML content of the webpage
page = requests.get(url.strip(), headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
# Get the price using BeautifulSoup
price = soup.find("span", class_="prc-dsc").get_text()
price = float(price.replace("TL","").replace(",","."))
# Compare the current price to the previous price
if price != previous_price:
# Send a message via Telegram API
message = f"The price of {url} has changed to {price} TL"
send_message(message)
# Check
previous_price = price
time.sleep(60)
urls.txt içindeki urlleri 60 saniyede bir kontrol edip fiyat değişikliği var ise telegramdan mesaj göndermesini yapacak bir python kodu yazmaya çalışıyorum. Bu şekilde bir kod yazdım fakat bu şekilde olunca 60 saniyede bir güncel fiyatları gönderiyor. Ben ise 60 saniyede bir kontrol edip, fiyat değişikliği varsa göndermesini istiyorum.
Şimdiden çok teşekkürler.