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 @@ -8,3 +8,4 @@
out
gen
node_modules
.DS_Store
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
## 此fork与原版的不同
增加了全球、其他国家、现存数量、每日增减的数据。国内后疫情时代,我们更希望关注的大多是世界疫情。

PR其实发了,但是原作者迟迟不merge,故自己写了。希望原作者如果看到请merge一下~

## 新冠病患数据的 Bitbar 插件

<img src="https://tva1.sinaimg.cn/large/006tNbRwly1gbchjabjxrj30si0pu1kx.jpg" alt="长这样" width="500">
<img src="https://github.com/SkyYkb/covid-19-bitbar-plugin/raw/master/screenshot.png" alt="长这样" width="500">

### 前提
- macOS
Expand Down
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 95 additions & 12 deletions wuhan.10s.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#!/usr/local/bin/python3
#!/usr/bin/python3
# coding=utf-8

# <bitbar.title>Wuhan pneumonia data</bitbar.title>
# <bitbar.version>v0.2</bitbar.version>
# <bitbar.author>Yifen Wu</bitbar.author>
# <bitbar.author.github>Anthonyeef</bitbar.author.github>
# <bitbar.desc>Wuhan pneumonia is spreading in the world, mainly in China. This plugin will show information (people having pneumonia, people dead because of pneumonia, and people who are cured from this pneumonia) for each province in China.</bitbar.desc>
# <bitbar.image>https://tva1.sinaimg.cn/large/006tNbRwly1gbccqabcaoj30tw0lc4l6.jpg</bitbar.image>
# <bitbar.image>https://raw.githubusercontent.com/SkyYkb/covid-19-bitbar-plugin/master/screenshot.png</bitbar.image>
# <bitbar.dependencies>python</bitbar.dependencies>
# <bitbar.abouturl>https://github.com/Anthonyeef/wuhan-virus-bitbar-plugin</bitbar.abouturl>
# <bitbar.abouturl>https://github.com/SkyYkb/wuhan-virus-bitbar-plugin</bitbar.abouturl>

import requests
import json
import os
import time

# 填写想看到的省份的名字,如
# targetProvinceName = {"北京", "湖北", "广东"}
Expand All @@ -21,9 +22,11 @@

# 除了 targetProvinceName 之外,还想额外看到的省份
# 如果不填则不会展示
additionProvinceName = {"北京", "广东", "上海"}
additionProvinceName = {}

# 武汉加油
# 除了中国之外,还想额外看到的国家
additionCountryName = {"美国", "塞尔维亚", "印度", "俄罗斯", "澳大利亚", "日本"}
# 武汉加油,世界加油


def showCountryInfo(dataEntry, textColor):
Expand All @@ -33,6 +36,7 @@ def showCountryInfo(dataEntry, textColor):
countrySusCount = dataEntry.get('sustotal')
countryCureCount = dataEntry.get('curetotal')
countryDeathCount = dataEntry.get('deathtotal')
countryConfirmExist = dataEntry.get('econNum')

countryConfirmSum = 0
countrySusSum = 0
Expand All @@ -57,30 +61,86 @@ def showCountryInfo(dataEntry, textColor):
if countryDeathSum > int(countryDeathCount):
countryDeathCount = str(countryDeathSum)

displayString = "全国 确: %s 疑: %s 亡: %s 愈 %s" % (
countryConfirmCount, countrySusCount, countryDeathCount, countryCureCount)
displayString = "全国 现: %s 确: %s 疑: %s 亡: %s 愈: %s | color=" % (
countryConfirmExist, countryConfirmCount, countrySusCount, countryDeathCount, countryCureCount) + textColor

print(displayString)
print('---')


def showDailyInfo(add_dailyEntry, textColor):

dailyAddConfirm = add_dailyEntry.get('addcon')
dailyAddSus = add_dailyEntry.get('addsus')
dailyAddCure = add_dailyEntry.get('addcure')
dailyAddDeath = add_dailyEntry.get('adddeath')
displayAddString = "全国新增 确: %s 疑: %s 亡: %s 愈: %s" % (
dailyAddConfirm, dailyAddSus, dailyAddDeath, dailyAddCure)
print(displayAddString + ' | color=' + textColor)


def showProvinceInfo(province, textColor):
provinceName = province.get('name')
provinceNowConfirmedCount = province.get('econNum')
provinceConfirmedCount = province.get('value')
provinceDeadCount = province.get('deathNum')
provinceCuredCount = province.get('cureNum')

displayString = "%s 确: %s 亡: %s 愈: %s" % (
provinceName, provinceConfirmedCount, provinceDeadCount, provinceCuredCount)
displayString = "%s 现: %s 确: %s 亡: %s 愈: %s" % (
provinceName, provinceNowConfirmedCount, provinceConfirmedCount, provinceDeadCount, provinceCuredCount)
print(displayString)

dailyAddList = province.get('adddaily')
dailyAddStr = "新增 确: %s 亡: %s 愈: %s" % (dailyAddList.get(
'conadd'), dailyAddList.get('deathadd'), dailyAddList.get('cureadd'))
print('--' + dailyAddStr + ' | color=' + textColor)

cityList = province.get('city')
for city in cityList:
cityDataStr = "%s 确:%s 亡:%s 愈:%s" % (city.get('name'), city.get(
cityDataStr = "%s 现: %s 确:%s 亡:%s 愈:%s" % (city.get('name'), city.get('econNum'), city.get(
'conNum'), city.get('deathNum'), city.get('cureNum'))
print('--' + cityDataStr + ' | color=' + textColor)


def showGlobalInfo(dataEntry, otherEntry, textColor):
dataTime = dataEntry.get('cachetime')
print('COVID-19 全球疫情数据统计 @%s | color=gray' % dataTime)
globalConfirmCount = otherEntry.get('certain')
globalCureCount = otherEntry.get('recure')
globalDeathCount = otherEntry.get('die')
globalNowConfirmedCount = otherEntry.get('ecertain')
globalAddConfirm = otherEntry.get('certain_inc')
globalAddNowCon = otherEntry.get('ecertain_inc')
globalAddCure = otherEntry.get('recure_inc')
globalAddDeath = otherEntry.get('die_inc')

# 感谢Bash版作者的思路
print('💊确诊:%s (%s) | color=#DC143C' %
(globalConfirmCount, globalAddConfirm))
print('😷现存:%s (%s)| color=#FFA500' %
(globalNowConfirmedCount, globalAddNowCon))
print('🍂死亡:%s (%s) | color=#FF7F50' % (globalDeathCount, globalAddDeath))
print('🍀治愈:%s (%s) | color=#32CD32' % (globalCureCount, globalAddCure))


def showOtherInfo(otherCEntry, textColor):
countryName = otherCEntry.get('name')
otherConfirmCount = otherCEntry.get('conNum')
otherCureCount = otherCEntry.get('cureNum')
otherSusCount = otherCEntry.get('susNum')
otherDeathCount = otherCEntry.get('deathNum')
otherNowConfirmedCount = otherCEntry.get('econNum')
otherStr = "%s 确: %s 疑: %s 亡: %s 愈: %s 现: %s" % (
countryName, otherConfirmCount, otherSusCount, otherDeathCount, otherCureCount, otherNowConfirmedCount)
print(otherStr + ' | color=' + textColor)
otherAddConfirm = otherCEntry.get('conadd')
otherAddCure = otherCEntry.get('cureadd')
otherAddDeath = otherCEntry.get('deathadd')
otherAddSus = otherCEntry.get('susadd')
otherAddStr = "新增 确: %s 疑: %s 亡: %s 愈: %s" % (
otherAddConfirm, otherAddSus, otherAddDeath, otherAddCure)
print('--' + otherAddStr + ' | color=' + textColor)


def main():
bitBarDarkMode = os.getenv('BitBarDarkMode', 0)
textColor = "black"
Expand All @@ -93,9 +153,25 @@ def main():

jsonData = json.loads(response.text)
dataEntry = jsonData.get('data')
# add_dailyEntry = dataEntry.get('add_daily')
otherEntry = dataEntry.get('othertotal')
otherCEntry = dataEntry.get('otherlist')
provinceList = dataEntry.get('list')

print('新冠疫情')
print('---')
showGlobalInfo(dataEntry, otherEntry, textColor)
showCountryInfo(dataEntry, textColor)
# showDailyInfo(add_dailyEntry, textColor)
# 功能为显示国内每日新增数据,但是后来发现数据出现问题,得到的是累计数据,遂去除

if len(additionCountryName) > 0:
print('---')
for country in otherCEntry:
counrtyName = country.get('name')
if counrtyName in additionCountryName:
showOtherInfo(country, textColor)
print('---')

if len(targetProvinceName) > 0:
for province in provinceList:
Expand All @@ -116,7 +192,14 @@ def main():
if provinceName in additionProvinceName:
showProvinceInfo(province, textColor)

print('---')
print('丁香园疫情地图 | href=https://ncov.dxy.cn/ncovh5/view/pneumonia')
print('百度疫情地图 | href=https://voice.baidu.com/act/newpneumonia/newpneumonia')
print('网易疫情地图 | href=http://news.163.com/special/epidemic/')
print('知乎疫情地图 | href=https://www.zhihu.com/2019-nCoV/trends#map')
print('---')
print('刷新... | refresh=true')


if __name__ == "__main__":
main()