forked from jpcnmm/Scripting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Appprice.js
45 lines (42 loc) · 1.64 KB
/
Appprice.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
/*using surge cron*/
const region = "vn"
const appIds = ["1312014438", "1423330822", "1085978097"]
var cacheData = $persistentStore.read()
if (!cacheData) {
cacheData = {}
} else {
cacheData = JSON.parse(cacheData)
}
$httpClient.post('https://itunes.apple.com/lookup?id=' + appIds + "&country=" + region, function (error, response, data) {
if (error) {
console.log(error);
$notification.post("App Pricer", "获取价格失败")
$done()
} else {
let appData = JSON.parse(data).results
let priceChanged = ""
let newAppAdded = ""
for (var i = 0; i < appData.length; i++) {
if (cacheData[appData[i].trackId]) {
if (appData[i].formattedPrice != cacheData[appData[i].trackId].price) {
priceChanged = priceChanged + "🏷 " + appData[i].trackName + " " + cacheData[appData[i].trackId].price + " → " + appData[i].formattedPrice + "\n"
cacheData[appData[i].trackId].price = appData[i].formattedPrice
}
} else {
newAppAdded = newAppAdded + "🏷 " + appData[i].trackName + " " + appData[i].formattedPrice + "\n"
cacheData[appData[i].trackId] = {
name: appData[i].trackName,
price: appData[i].formattedPrice
}
}
}
if (priceChanged) {
$notification.post("Price Changed", "", priceChanged)
}
if (newAppAdded) {
$notification.post("New Apps Added", "", newAppAdded)
}
$persistentStore.write(JSON.stringify(cacheData))
$done()
}
})