Skip to content

Commit dfef054

Browse files
authored
Merge pull request #783 from iam-shanmukha/covid19_telegram_bot-#767
Fix #767
2 parents 7a5233f + 3dae10e commit dfef054

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

covid19_telegram_bot/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# covid19_telegram_bot
2+
3+
covid19_telegram_bot posts real time covid19 updates to a telegram channel. It updates the data from http://worldometers.info
4+
5+
## Setup instructions
6+
7+
1. Go to https://t.me/BotFather
8+
2. Create NewBot and get API Token
9+
3. Add bot to a Telegram Channel
10+
4. [Get](https://stackoverflow.com/a/67274937/14117093) Telegram Channel chat ID
11+
- Use the link below to get Chat ID
12+
`https://api.telegram.org/bot<BOT_TOKEN>/getUpdates`
13+
5. Replace `"YOUR-TOKEN-HERE"` with your token and `"GROUP-CHAT-ID-HERE"` with chat id.
14+
6. Run the Code
15+
16+
## Output
17+
![Screenshot from 2021-10-20 11-09-28](https://user-images.githubusercontent.com/50124557/138034482-dbf559ea-34fe-476c-a4c3-6772bdbd2820.png)
18+
19+
- Bot Telegram Channel: https://www.t.me/covid_bot_india
20+
21+
## Author(s)
22+
23+
Shanmukha Vishnu
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
Author: Shanmukha Vishnu
3+
Github: @iam-shanmukha
4+
"""
5+
import requests
6+
from covid import Covid
7+
8+
previous_data = []
9+
# #######################Telegram###########################
10+
11+
12+
def send_msg(text):
13+
token = "YOUR-TOKEN-HERE"
14+
chat_id = "GROUP-CHAT-ID-HERE"
15+
url_req = (
16+
'https://api.telegram.org/'
17+
'bot' + token + '/sendMessage' + '?chat_id'
18+
'=' + chat_id + "&text=" + text)
19+
results = requests.get(url_req)
20+
print(results.json())
21+
22+
23+
# ##---One Time Run---###
24+
covid = Covid(source="worldometers")
25+
India_cases = covid.get_status_by_country_name("india")
26+
stat = (
27+
"\n".join(
28+
"{} : \t{}".format(k, v)
29+
for k, v in India_cases.items()
30+
if not k.startswith(("population", "total"))
31+
)
32+
+ "\n#IndiaFightsCorona"
33+
)
34+
35+
previous_data.append(stat)
36+
while 1:
37+
covid = Covid(source="worldometers")
38+
India_cases = covid.get_status_by_country_name("india")
39+
stat = (
40+
"\n".join(
41+
"{} : \t{}".format(k, v)
42+
for k, v in India_cases.items()
43+
if not k.startswith(("population", "total"))
44+
)
45+
+ "\n#IndiaFightsCorona"
46+
)
47+
if stat in previous_data:
48+
print("Duplicate")
49+
else:
50+
print("msg _posted")
51+
previous_data = []
52+
previous_data.append(stat)
53+
send_msg(stat)

covid19_telegram_bot/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
covid==2.3.0

0 commit comments

Comments
 (0)