Разовая отправка события из FlashScore в телеграм с помощью Python
Подскажите как сделать отправку события в телеграм разово при выполнении конкретных условий, а не с помощью while True
код прилагаю:
import time
import requests
from selenium import webdriver
from bs4 import BeautifulSoup
driver=webdriver.Firefox()
driver.get("https://www.flashscore.ru")
time.sleep(10)
elements = driver.find_elements_by_css_selector("div.tabs__tab")
elements[1].click()
def track_matches(container):
soup = BeautifulSoup(container, "html.parser")
matches = soup.select(".event__match.event__match--live.event__match--oneLine")
for match in matches:
time_match = match.select_one("div.event__stage--block")
total = match.select_one("div.event__scores.fontBold")
id_match = match["id"].split("_")[-1]
if time_match and total:
time_match = time_match.text.strip()
total = total.text.strip()
if time_match.isdigit():
time_match = int(time_match)
total_sum = sum(list(map(lambda x: int(x.strip()), total.split("-"))))
print(time_match, total_sum)
url = "https://www.flashscore.ru/match/{}/#match-summary".format(id_match)
if time_match > 65 and total_sum == 0:
print(time_match, total, url)
api_token = '******'
requests.get('https://api.telegram.org/bot{}/sendMessage'.format(api_token), params=dict(
chat_id='******',
text = url + ' Тотал > 0.5 в матче '
))
temp_hash = 0
while True:
container = driver.find_element_by_css_selector("div[id=live-table]").get_attribute("innerHTML")
if temp_hash != hash(container):
track_matches(container)
temp_hash = hash(container)