Guest User

Untitled

a guest
Mar 15th, 2020
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.68 KB | None | 0 0
  1. import requests
  2. import time
  3.  
  4. token = "" #your telegram bot token
  5. telegramApi = "https://api.telegram.org/bot{}/".format(token)
  6. offset = "None"
  7.  
  8. def refresh(country):
  9.     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)
  10.     response = requests.get(apiurl)
  11.     etat = response.ok
  12.     while etat == False:
  13.         response = requests.get(apiurl)
  14.         etat = response.ok
  15.     result=response.json()["features"][0]["attributes"]
  16.     print("Refreshed")
  17.     return result["Confirmed"], result["Deaths"], result["Recovered"]
  18.  
  19. def sendAlarm(chatId, result, country):
  20.     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]))
  21.     if r.ok == True:
  22.      print("Sent!")
  23.  
  24.  
  25. country = "France"
  26. chatId =  # your chatID
  27. refreshTime = 1 #in minutes
  28. actualValue = 0
  29. 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))
  30. while True:
  31.     newValue = refresh(country)
  32.     if actualValue != newValue:
  33.         sendAlarm(chatId, newValue, country)
  34.         actualValue = newValue
  35.     time.sleep(refreshTime*60)
Advertisement
Add Comment
Please, Sign In to add comment