Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,4 @@ cython_debug/
# static files generated from Django application using `collectstatic`
media
static
.idea
22 changes: 11 additions & 11 deletions corona_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logging.basicConfig(format=FORMAT, level=logging.DEBUG, filename='bot.log', filemode='a')

URL = 'https://www.mohfw.gov.in/'
SHORT_HEADERS = ['Sno', 'State','In','Fr','Cd','Dt']
SHORT_HEADERS = ['Sno', 'State', 'In', 'Fr', 'Cd', 'Dt']
FILE_NAME = 'corona_india_data.json'
extract_contents = lambda row: [x.text.replace('\n', '') for x in row]

Expand All @@ -26,15 +26,15 @@ def load():
with open(FILE_NAME, 'r') as f:
res = json.load(f)
return res


if __name__ == '__main__':
parser = argparse.ArgumentParser()

parser = argparse.ArgumentParser()
parser.add_argument('--states', default=',')
args = parser.parse_args()
interested_states = args.states.split(',')

current_time = datetime.datetime.now().strftime('%d/%m/%Y %H:%M')
info = []

Expand All @@ -52,12 +52,12 @@ def load():
# last row
stat = ['', *stat]
stats.append(stat)
elif any([s.lower() in stat[1].lower() for s in interested_states]):
elif len(stat) >= 2 and any([s.lower() in stat[1].lower() for s in interested_states]):
stats.append(stat)

past_data = load()
cur_data = {x[1]: {current_time: x[2:]} for x in stats}

changed = False

for state in cur_data:
Expand All @@ -72,7 +72,7 @@ def load():
if past != cur:
changed = True
info.append(f'Change for {state}: {past}->{cur}')

events_info = ''
for event in info:
logging.warning(event)
Expand All @@ -89,5 +89,5 @@ def load():
slack_text = f'Please find CoronaVirus Summary for India below:\n{events_info}\n```{table}```'
slacker()(slack_text)
except Exception as e:
logging.exception('oops, corono script failed.')
slacker()(f'Exception occured: [{e}]')
logging.exception('oops, corona script failed.')
slacker()(f'Exception occurred: [{e}]')
13 changes: 8 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@
## Installation
- You need Python
- You need a Slack account + Slack Webhook to send slack notifications to your account
- Install dependencies by running
- Making virtual environment and activating it
```bash
pip install tabulate
pip install requests
pip install beautifulsoup4
python3 -m venv venv
source ./venv/bin/activate
```
- Installing the dependencies
```bash
pip install -r requirements.txt
```
- Clone this repo and create auth.py
```bash
Expand All @@ -38,7 +41,7 @@ touch auth.py
```
- Write your Slack Webhook into auth.py
```python
DEFAULT_SLACK_WEBHOOK = 'https://hooks.slack.com/services/<your custome webhook url>'
DEFAULT_SLACK_WEBHOOK = 'https://hooks.slack.com/services/<your customer webhook url>'
```
- Setup the cron job to receive updates whenever something changes
```bash
Expand Down
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tabulate
requests
beautifulsoup4