File tree Expand file tree Collapse file tree 3 files changed +75
-0
lines changed Expand file tree Collapse file tree 3 files changed +75
-0
lines changed Original file line number Diff line number Diff line change
1
+ # covid19_telegram_bot.py
2
+ Bot Telegram Channel: https://www.t.me/covid_bot_india </br >
3
+ # Dependencies
4
+ ```
5
+ pip install covid
6
+ ```
7
+ # Usage
8
+ 1 . Go to https://t.me/BotFather
9
+ 2 . Create NewBot and get API Token
10
+ 3 . Add bot to a Telegram Channel
11
+ 4 . [ Get] ( https://stackoverflow.com/a/67274937/14117093 ) Telegram Channel chat ID
12
+ - Use the link below to get Chat ID
13
+ ``` https://api.telegram.org/bot<BOT_TOKEN>/getUpdates ```
14
+ 5 . Replace ` "YOUR-TOKEN-HERE" ` with your token and ` "GROUP-CHAT-ID-HERE" ` with chat id.
15
+ 6 . Run the Code
16
+
Original file line number Diff line number Diff line change
1
+ """
2
+ Author: Shanmukha Vishnu
3
+ Github: @iam-shanmukha
4
+ """
5
+ import requests
6
+ from covid import Covid
7
+ from os import *
8
+
9
+ previous_data = []
10
+ # #######################Telegram###########################
11
+
12
+
13
+ def send_msg (text ):
14
+ token = "YOUR-TOKEN-HERE"
15
+ chat_id = "GROUP-CHAT-ID-HERE"
16
+ url_req = (
17
+ "https://api.telegram.org/bot" +
18
+ token +
19
+ "/sendMessage" +
20
+ "?chat_id=" +
21
+ chat_id +
22
+ "&text=" +
23
+ text
24
+ )
25
+ results = requests .get (url_req )
26
+ print (results .json ())
27
+
28
+
29
+ # ##---One Time Run---###
30
+ covid = Covid (source = "worldometers" )
31
+ India_cases = covid .get_status_by_country_name ("india" )
32
+ stat = (
33
+ "\n " .join (
34
+ "{} : \t {}" .format (k , v )
35
+ for k , v in India_cases .items ()
36
+ if not k .startswith (("population" , "total" ))
37
+ ) +
38
+ "\n #IndiaFightsCorona"
39
+ )
40
+ previous_data .append (stat )
41
+ while 1 :
42
+ covid = Covid (source = "worldometers" )
43
+ India_cases = covid .get_status_by_country_name ("india" )
44
+ stat = (
45
+ "\n " .join (
46
+ "{} : \t {}" .format (k , v )
47
+ for k , v in India_cases .items ()
48
+ if not k .startswith (("population" , "total" ))
49
+ ) +
50
+ "\n #IndiaFightsCorona"
51
+ )
52
+ if stat in previous_data :
53
+ print ("Duplicate" )
54
+ else :
55
+ print ("msg _posted" )
56
+ previous_data = []
57
+ previous_data .append (stat )
58
+ send_msg (stat )
Original file line number Diff line number Diff line change
1
+ covid == 2.3.0
You can’t perform that action at this time.
0 commit comments