-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnCov-2019-CHN.py
executable file
·72 lines (55 loc) · 2.51 KB
/
nCov-2019-CHN.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env PYTHONIOENCODING=UTF-8 /Users/chazeon/.pyenv/shims/python3
# <bitbar.title>NYC nCov Report</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>Chazeon Luo</bitbar.author>
# <bitbar.author.github>chazeon</bitbar.author.github>
data_url = "https://ncov.dxy.cn/ncovh5/view/pneumonia"
import sys, re, urllib.parse, json
from pathlib import Path
import textwrap
import dateutil.parser
sys.path.append(str(Path(__file__).parent.parent / "libs"))
import bitbar
def get_info():
import requests, bs4
resp = requests.get(data_url)
doc = resp.content
soup = bs4.BeautifulSoup(doc, "html.parser")
script = soup.find("script", id="getStatisticsService")
res = re.search(r"try { window.getStatisticsService = (.*)}catch\(e\){}", str(script))
return json.loads(res.group(1))
info = get_info()
cases_count = {
"confirmed": info['confirmedCount'],
"suspected": info['suspectedCount'],
"serious": info['seriousCount'],
"dead": info['deadCount'],
"cured": info['curedCount']
}
pkg = bitbar.BitBarMessagePack(f"😷{cases_count['confirmed']}")
pkg.append("丁香园 2019 新冠统计", { "href": data_url})
pkg.append("---")
pkg.append(f"确诊: {cases_count['confirmed']:7,d}", { "font":"'SF Mono'", "size": 12, "color": "gray"})
pkg.append(f"疑似: {cases_count['suspected']:7,d}", { "font":"'SF Mono'", "size": 12, "color": "gray"})
pkg.append(f"重症: {cases_count['serious'] :7,d}", { "font":"'SF Mono'", "size": 12, "color": "red"})
pkg.append(f"死亡: {cases_count['dead'] :7,d}", { "font":"'SF Mono'", "size": 12, "color": "black"})
pkg.append(f"治愈: {cases_count['cured'] :7,d}", { "font":"'SF Mono'", "size": 12, "color": "green"})
print(str(pkg))
exit()
news = get_news()
pkg.append(f"Total {sum(cases.values())} cases", { "href": table_url})
for key, val in cases.items():
pkg.append(f"{key}: {val}", {"color": "gray"})
pkg.append("---")
pkg.append(f"Twitter @nycHealthy", {"href": "https://twitter.com/nycHealthy"})
news_parent = bitbar.BitBarMessageParent(f"NYCHealth News", {"href": news_url})
pkg.append(news_parent)
for news_piece in news:
title = news_piece["title"]
title = re.sub(r"^New York City Reports", "", title)
title = re.sub(r"New York City", "NYC", title)
title = textwrap.shorten(title, 50, placeholder=" ...")
link = urllib.parse.urljoin(news_url, news_piece["link"])
date = news_piece["date"].strftime("%m/%d")
msg = bitbar.BitBarMessage(f"({date}) {title}", {"href": link})
news_parent.append(msg)