-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (45 loc) · 1.58 KB
/
index.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
46
47
const express = require("express");
const app = express();
const puppeteer = require("puppeteer");
const fs = require('fs');
let config = fs.readFileSync('config.json');
let delete1 = JSON.parse(config).delete;
async function fetchDeprem(){
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("http://www.koeri.boun.edu.tr/scripts/lst0.asp");
const src = await page.evaluate(() => {
return document.getElementsByTagName("pre").item(0).innerText;
});
let text = src.replace(delete1, '');
text = text.split('\n');
let depremler = [];
for(let i = 0; 498 > i; i++){
depremler[i] = {
"Tarih" : text[i].slice(0, 10).trim(),
"Saat" : text[i].slice(11, 19).trim(),
"Enlem" : text[i].slice(21, 28).trim(),
"Boylam" : text[i].slice(31, 38).trim(),
"Derinlik" : text[i].slice(46, 50).trim(),
"MD" : text[i].slice(55, 59).trim(),
"ML" : text[i].slice(60, 64).trim(),
"MW" : text[i].slice(65, 69).trim(),
"Yer" : text[i].slice(71, 121).trim(),
"Niteligi" : text[i].slice(121, ),
}
}
await browser.close()
return depremler
}
app.get('/', (req, res) => {
fetchDeprem().then(data => {
res.json({
"depremler" : data
})
})
});
const port = process.env.PORT || 3000;
const listener = app.listen(port , (err) => {
if (err) throw err;
console.log(`API ${listener.address().port} portunda hazır!`);
});