-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdl-raw-data.js
More file actions
37 lines (35 loc) · 1.44 KB
/
dl-raw-data.js
File metadata and controls
37 lines (35 loc) · 1.44 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
29
30
31
32
33
34
35
36
37
const fs = require('fs').promises; // Use the promise-based version of fs
require('dotenv').config()
const axios = require('axios');
const { spawnSync } = require('child_process');
async function dlRawData() {
try {
console.log('API KEY', process.env.MATOMO_API_KEY)
fs.mkdir('data')
const filterLimit = 1000
let offset = 0
while (true) {
console.log(offset)
const postRequestData = {
token_auth: process.env.MATOMO_API_KEY,
idSite: 23,
period: 'day',
date: 'yesterday',
filter_limit: filterLimit,
filter_offset: offset
}
const response = spawnSync(
`curl -X POST "https://ethereumfoundation.matomo.cloud/index.php?module=API&method=Live.getLastVisitsDetails&format=JSON" --data "idSite=23&period=day&date=yesterday&filter_limit=${filterLimit}&filter_offset=${offset}&token_auth=${process.env.MATOMO_API_KEY}" --output ./data/matomo_${offset}.json`, { shell:true })
const data = await fs.readFile(`data/matomo_${offset}.json`, 'utf8');
if (data === '[]') {
break
}
offset = offset + filterLimit
}
} catch (error) {
console.error('Error loading the JSON file:', error);
throw error; // Rethrow the error if needed
}
}
console.log('dlRawData')
dlRawData()