-
Notifications
You must be signed in to change notification settings - Fork 0
/
Object.gs
100 lines (89 loc) · 2.34 KB
/
Object.gs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
function getTextContent(res, elem, bIgnore)
{
return getTextContents(res, elem, bIgnore)[0];
}
function getTextContents(res, elem, bIgnore)
{
if(bIgnore)
{
var temps = Parser.data(res).from('<' + elem).to('/' + elem + '>').iterate();
for(var i=0; i<temps.length; i++)
{
temps[i] = Parser.data(temps[i]).from('>').to('<').build();
}
return temps;
}
else
{
return Parser.data(res).from('<' + elem + '>').to('</' + elem + '>').iterate();
}
}
function getChildText(elem, name, text)
{
if(elem.getName() == name) return elem.getText();
return text;
}
function compileIntList(root)
{
let result = [];
for(var i=0; i<root.length; i++)
{
if(root[i][0] != "")
{
result.push(String(Math.floor(root[i][0])));
}
}
return result;
}
function removeTags(str)
{
let splitbuf = str.split('>');
for(var i=splitbuf.length-1;i>=0;i--)
{
splitbuf[i] = splitbuf[i].split('<')[0];
if(splitbuf[i].replace(/[\n\s]/g, '') == "")
splitbuf.splice(i,1);
}
return splitbuf;
}
function postWebhook(payload, property, suffix="")
{
let url = PropertiesService.getScriptProperties().getProperty(property) + suffix;
let options = {"method": "post", "headers": { 'Content-type': "application/json" }, "payload": JSON.stringify(payload)};
UrlFetchApp.fetch(url, options);
}
function getUnixTime(time)
{
formatGMT = Utilities.formatDate(time, 'GMT', 'dd MMM yyyy HH:mm:ss z');
unixDate = Date.parse(formatGMT) / (10**3);
return unixDate;
}
function setupRSS(url)
{
let xml = UrlFetchApp.fetch(url).getContentText();
let root = XmlService.parse(xml).getRootElement();
return root.getChildren();
}
function dynamicFetchApp(url){
let options = {
url: url,
renderType: "HTML",
outputAsJson: true
};
let payload = encodeURIComponent(JSON.stringify(options));
const apiKey = PropertiesService.getScriptProperties().getProperty("API_KEY");
let apiUrl = "https://phantomjscloud.com/api/browser/v2/"+ apiKey +"/?request=" + payload;
let res = UrlFetchApp.fetch(apiUrl).getContentText();
return res;
}
function dynamicFetch(url)
{
let res = dynamicFetchApp(url);
return JSON.parse(res)["content"]["data"];
}
function getNumProperty(name, defaultValue=0)
{
let num = Number(PropertiesService.getScriptProperties().getProperty(name));
if(!num) return defaultValue;
return num;
}