Skip to content

Commit 7f09a56

Browse files
committed
Fix #767
- Added covid19_telegram_bot
1 parent 102454a commit 7f09a56

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

covid19_telegram_bot/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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)

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)