-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (35 loc) · 1.17 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
const fetch = require('node-fetch')
const csv = require('csvtojson')
const request = require('request')
const baseUrl = 'http://gs.statcounter.com/chart.php?'
var fs = require('fs')
const currentTime = new Date()
let month = ''
if ((date = new Date().getDate() > 1)) {
month = ('0' + (currentTime.getMonth() + 1)).slice(-2)
} else {
month = ('0' + (currentTime.getMonth() + 0)).slice(-2)
}
const year = currentTime.getFullYear()
const endpoint = `${baseUrl}${year}${month}=undefined&bar=1&device=Desktop%20%26%20Mobile%20%26%20Tablet&device_hidden=desktop%2Bmobile%2Btablet&statType_hidden=browser_version®ion_hidden=SE&granularity=monthly&statType=Browser%20Version®ion=Sweden&fromInt=${year}${month}&toInt=${year}${month}&fromMonthYear=${year}-${month}&toMonthYear=${year}-${month}&multi-device=true&csv=1`
fetch(endpoint).then(data => {
csv()
.fromStream(request.get(endpoint))
.subscribe(json => {
return new Promise((resolve, reject) => {
resolve('done')
})
})
.then(result => {
fs.writeFile(
'./data/browsers.json',
JSON.stringify(result),
'utf8',
(callback = err => {
if (err) {
return console.log(err)
}
})
)
})
})