-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNews.js
More file actions
74 lines (51 loc) · 1.47 KB
/
News.js
File metadata and controls
74 lines (51 loc) · 1.47 KB
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
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: orange; icon-glyph: magic;
async function createWidget(tNow)
{
let widget = new ListWidget()
let df = new DateFormatter()
df.dateFormat = "HH:mm:ss"
const wtDate = widget.addText(df.string(tNow))
wtDate.font = Font.lightRoundedSystemFont(12)
await request("http://www.techmeme.com/feed.xml")
return widget
}
async function run()
{
// get information to display
let gDate = new Date()
// create the widget and associate with script
let widget = await createWidget(gDate)
Script.setWidget(widget)
// finish execution and display preview
if (config.runsInApp) widget.presentMedium()
Script.complete()
}
await run()
async function request(url)
{
const fm = FileManager.iCloud()
let fileName = "techmeme.js"
let filePath = fm.documentsDirectory() + "/storage" + "/" + fileName
var jInfo
console.log("************")
if(fm.fileExists(filePath))
{
console.log("file found: " + fileName)
jInfo = JSON.parse(fm.readString(filePath))
console.log(jInfo)
return jInfo
}
var req = new Request(url)
try {
console.log("request sent: " + JSON.stringify(req))
jInfo = await req.loadString()
} catch (error) {
console.log(error)
return
}
console.log(jInfo)
fm.writeString(filePath, jInfo)
return jInfo
}