-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathziraat.js
More file actions
28 lines (25 loc) · 1.31 KB
/
Copy pathziraat.js
File metadata and controls
28 lines (25 loc) · 1.31 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
import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
import { format } from "https://deno.land/std@0.222.1/datetime/mod.ts";
const filename = Deno.args[0]
await Deno.remove(filename)
const zaman = Math.floor(new Date().getTime() / 1000)
const file = await Deno.open("ziraat.csv", { append: true });
for (const [url, selector, kurName] of [
["https://www.ziraatbank.com.tr/tr/_layouts/15/Ziraat/FaizOranlari/Ajax.aspx/GetDovizKurlari", '[data-id="rdIntBranchDoviz"] tr', null],
["https://www.ziraatbank.com.tr/tr/_layouts/15/Ziraat/FaizOranlari/Ajax.aspx/GetAltinFiyatlari", '[data-id="rdIntBranchAltin"] tr:nth-child(2)', "XAU"]
]) {
let html = (await (await fetch(url, {
"headers": { "Content-Type": "core/json", },
"body": JSON.stringify({ date: format(new Date(), "yyyy-MM-dd") }),
"method": "POST"
})).json())?.d?.Data
let document = new DOMParser().parseFromString(html, "text/html")
document.querySelectorAll(selector).forEach(async tr => {
const tds = [...tr.querySelectorAll("td")]
if (tds.length < 4) return
const [kur, alis, satis] = [0, 2, 3].map(i => tds[i].textContent.replaceAll(",", "."))
const str = `${zaman},${kurName ?? kur},${alis},${satis}\n`
await file.write(new TextEncoder().encode(str))
})
}
file.close()