Skip to content

Instantly share code, notes, and snippets.

@vexdy
Last active January 15, 2022 07:46
Show Gist options
  • Save vexdy/940afc671fa4a06d1455dce5d12fe62b to your computer and use it in GitHub Desktop.
Save vexdy/940afc671fa4a06d1455dce5d12fe62b to your computer and use it in GitHub Desktop.
Get latest 500 earthquakes from Kandilli Rasathanesi's website
// No need for PHP APIs when you have nodejs :)
const fetch = require('node-fetch');
const crypto = require('crypto');
const moment = require('moment');
let url = 'http://www.koeri.boun.edu.tr/scripts/lst2.asp';
fetch(url)
.then(res => res.text())
.then(body => {
let all_eqs = body.match(/<pre>([\s\S]*?)<\/pre>/)[0].replace('<pre>', '').replace('</pre>', '').split('\n').slice(7).join('\n').toString();
let eq_data = [];
function yer_ismi(arr) {
let yer = "";
let limit = 1;
if (arr[arr.length - 3].match(/REVIZE/g)) limit = 3;
for (i = 8; i < arr.length - limit; i++) {
yer += arr[i] + " "
};
return yer.slice(0, -1)
};
function revize_ismi(arr) {
let revize = "";
for (i = arr.length - 3; i < arr.length; i++) {
revize += arr[i] + " ";
};
return revize.slice(0, -2);
};
function md5(data) {
return crypto.createHash('md5').update(data).digest("hex");
};
all_eqs = all_eqs.split("\n").slice(0, -2);
all_eqs.forEach(el => {
el = el.replace(/\s\s+/g, ' ').split(' ');
eq_data.push({tarih: el[0].split(".").reverse().join("/"), saat: el[1], milisaniye: moment(`${el[0].split(".").join("-")} ${el[1]}`).valueOf(), enlem: el[2], boylam: el[3], koordinatlar: [ parseFloat(el[2]), parseFloat(el[3]) ], derinlik: el[4], md: el[5], ml: el[6], mw: el[7], yer: yer_ismi(el), nitelik: el[el.length-1].match(/sel/g) ? 'İlksel' : revize_ismi(el), hash: md5(el[0] + el[1] + el[4] + el[5] + el[6] + el[7]), hash2: md5(el[2] + el[3]) })
});
console.log(eq_data[0]);
});
// Expected output:
/*
{
tarih: '14/05/2021',
saat: '13:19:50',
milisaniye: 1620987590000,
enlem: '36.8502',
boylam: '36.7330',
koordinatlar: [ 36.8502, 36.733 ],
derinlik: '7.1',
md: '-.-',
ml: '2.8',
mw: '-.-',
yer: 'DELIOSMAN-(KILIS)',
nitelik: 'İlksel',
hash: '350ccbdfa47bcfe667235287aac6a9bf',
hash2: '8c0aafbdc3f18d37c4e95eba06481abc'
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment