forked from openclimatefix/metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-mailchimp.js
32 lines (26 loc) · 839 Bytes
/
get-mailchimp.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
const axios = require('axios');
var fs = require('fs')
const FILENAME = 'data/mailchimp-subscribers.json'
axios.get('https://us20.api.mailchimp.com/3.0/lists/d56fc32a31', {
auth: {
username: "ofc-metrics",
password: process.env.MAILCHIMP_API_KEY
},
})
.then(response => {
fs.readFile(FILENAME, function (err, data) {
if (err) throw err;
var output = JSON.parse(data)
output.push({
x: new Date(),
y: response.data.stats.member_count
})
fs.writeFile(FILENAME, JSON.stringify(output), function (err) {
if (err) throw err;
console.log('Data was appended to file!');
});
})
})
.catch(error => {
console.log(error);
});