-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.gs
30 lines (26 loc) · 1.09 KB
/
main.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
function doGet() {
return HtmlService.createTemplateFromFile('index').evaluate();
}
function doPost() {
return null
}
function getHtmlData(url) {
const tmp = UrlFetchApp.fetch(url).getContentText();
return tmp;
}
function getParsedHtmlData(html, fromText, toText, iterate) {
if (iterate == 'build') return Parser.data(html).from(fromText).to(toText).build();
else return Parser.data(html).from(fromText).to(toText).iterate();
}
function getPrice(code) {
const KABUTAN = "https://kabutan.jp/";
let prices = [0, 0, 0];
let html = UrlFetchApp.fetch(KABUTAN).getContentText();
prices = Parser.data(html).from('class="price">').to('</td>').iterate();
for (let i in prices) prices[i] = prices[i].replace(/,|円/g, "");
if (code == "nikkei") return Number(prices[0]);
else if (code == "usdyen") return Number(prices[1]);
else if (code == "nydow") return Number(prices[2]);
html = UrlFetchApp.fetch(KABUTAN + `stock/?code=${code}`).getContentText();
return Number(Parser.data(html).from('<span class="kabuka">').to('</span>').build().replace(/,|円/g, ""));
}