forked from mvan231/Scriptable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Canada Covid Dark.js
54 lines (46 loc) · 1.56 KB
/
Canada Covid Dark.js
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
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: pink; icon-glyph: magic;
let widget = new ListWidget()
let url = "https://coronavirus-19-api.herokuapp.com/countries/Canada"
//load data from API
let req = new Request(url)
let json = await req.loadJSON()
//get background image
let imgReq = new Request('https://i.imgur.com/WYmGnnH.jpg')
//let img = await imgReq.loadImage()
log(json)
//get the data from the JSON
let todayCases = json['todayCases'].toString()
let todayDeaths = json['todayDeaths'].toString()
let recovered = json['recovered'].toString()
let active = json['active'].toString()
let deaths = json['deaths'].toString()
let cases = json['cases'].toString()
const date = new Date()
const widgetTitle = widget.addText("🦠 " + date.toLocaleDateString())
widgetTitle.font = Font.systemFont(15)
widgetTitle.textColor=Color.white()
//add items to the widget
addItem('total cases', cases)
addItem('total deaths', deaths)
addItem('active', active)
addItem('recovered', recovered)
addItem('cases today', todayCases)
addItem('deaths today', todayDeaths)
// Finalize widget settings
widget.setPadding(16,16,16,0)
widget.spacing = -2
//widget.backgroundImage=img
widget.backgroundColor=Color.black()
Script.setWidget(widget)
widget.presentSmall()
Script.complete()
function addItem(item,itemValue){
let val = widget.addText(itemValue)
val.font=Font.mediumRoundedSystemFont(12)
val.textColor=Color.lightGray()
const subt1 = widget.addText(item)
subt1.font = Font.systemFont(9)
subt1.textColor = Color.white()
}