This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
75 lines (61 loc) · 1.98 KB
/
__init__.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
72
73
74
# -*- coding: utf-8 -*-
"""Covid 19 Display"""
from albertv0 import *
import time
import os
import sys
import requests
# enable local module import
# relative imports don't work for some reason
sys.path.append(os.path.dirname(__file__))
__iid__ = "PythonInterface/v0.1"
__prettyname__ = "Covid19"
__version__ = "0.1"
__trigger__ = "covid"
__author__ = "cyd3r"
__dependencies__ = []
icon_recovered = iconLookup("face-cool")
icon_confirmed = iconLookup("face-sick")
icon_deaths = iconLookup("face-crying")
covid_data = None
keys = ["Confirmed", "Deaths", "Recovered"]
def initialize():
global covid_data
covid_data = requests.get("https://api.covid19api.com/summary").json()
def handleQuery(query):
if covid_data is None:
print("Covid19 data is not available")
return
if not query.isTriggered:
return
# avoid rate limiting
time.sleep(0.1)
if not query.isValid:
return
stripped = query.string.strip()
display_data = covid_data["Global"]
if stripped:
stripped = stripped.lower()
for country_data in covid_data["Countries"]:
if country_data["Country"].lower() == stripped or country_data["CountryCode"].lower() == stripped or country_data["Slug"].lower() == stripped:
display_data = country_data
break
items = []
for category in keys:
main_key = "New" + category
sub_key = "Total" + category
if category == "Confirmed":
icon_path = icon_confirmed
elif category == "Recovered":
icon_path = icon_recovered
elif category == "Deaths":
icon_path = icon_deaths
else:
# should not happen
continue
item = Item(id=__prettyname__,
icon=icon_path,
text="New {}: {}".format(category, display_data[main_key]),
subtext="Total {}: {}".format(category, display_data[sub_key]))
items.append(item)
return items