Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import time
- token = "" #your telegram bot token
- telegramApi = "https://api.telegram.org/bot{}/".format(token)
- offset = "None"
- def refresh(country):
- apiurl = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/ncov_cases/FeatureServer/1/query?f=json&where=(Confirmed%20%3E%200)%20AND%20(Deaths%3E0)%20AND%20(Country_Region%3D%27{}%27)&returnGeometry=false&spatialRel=esriSpatialRelIntersects&outFields=*&orderByFields=Deaths%20desc%2CCountry_Region%20asc%2CProvince_State%20asc&outSR=102100&resultOffset=0&resultRecordCount=250&cacheHint=true".format(country)
- response = requests.get(apiurl)
- etat = response.ok
- while etat == False:
- response = requests.get(apiurl)
- etat = response.ok
- result=response.json()["features"][0]["attributes"]
- print("Refreshed")
- return result["Confirmed"], result["Deaths"], result["Recovered"]
- def sendAlarm(chatId, result, country):
- r = requests.get(telegramApi+"sendMessage?chat_id={}&parse_mode=markdown&text=⚠️*ALERTE*⚠️\nNouveaux cas de contamination en {}!\n\nConfirmé: {}\nMorts: {}\nRécupéré: {}".format(chatId, country, result[0], result[1], result[2]))
- if r.ok == True:
- print("Sent!")
- country = "France"
- chatId = # your chatID
- refreshTime = 1 #in minutes
- actualValue = 0
- r = requests.get(telegramApi+"sendMessage?chat_id={}&parse_mode=markdown&text=Bonjour !\nJe vous annonce en temps réel l'évolution du corona virus(COVID-19) en {}".format(chatId, country))
- while True:
- newValue = refresh(country)
- if actualValue != newValue:
- sendAlarm(chatId, newValue, country)
- actualValue = newValue
- time.sleep(refreshTime*60)
Advertisement
Add Comment
Please, Sign In to add comment