forked from AnnaNishino/covid_automation
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jhu_update_checker.py
38 lines (32 loc) · 1.45 KB
/
jhu_update_checker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import json
import pandas as pd
import requests as rq
from datetime import datetime,timedelta, timezone, date
import time
def check_update():
url = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv'
df = pd.read_csv(url)
#データの最新日
upd_date = pd.to_datetime(df.columns[-1],format='%m/%d/%y').date()
#ほしい日付(日本時間でみて、更新作業当日の1日前まで確報が入ればOK)
prev_date = (datetime.utcnow()-timedelta(hours=15)).date()
#更新フラグ、通知
flag = True if upd_date >= prev_date else False
msg = (pd.to_datetime(upd_date).strftime('%m/%d')+'の確報値が更新されました') if flag else "確報値は未更新です"
return flag, msg
#初回チェック
update, text = check_update()
#未更新なら15時までトライ
while not update:
update, text = check_update()
if not update:
if ((datetime.utcnow() + timedelta(hours=9)).hour >15):
text = '15時までに確報値の更新が確認できませんでした。\n'
break
else:
time.sleep(60*3)
continue
text = '▼Johns Hopkins University (JHU)の世界の感染者・死者数:\n' + datetime.now(timezone(timedelta(hours=+9), 'JST')).strftime('%Y年%m月%d日 %H:%M') + "\n\n" + text
str = {"text":text}
with open('./sourcedata_update_log.json', 'w') as f:
json.dump(str, f, ensure_ascii=False)