-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateInfo.js
More file actions
27 lines (23 loc) · 733 Bytes
/
Copy pathupdateInfo.js
File metadata and controls
27 lines (23 loc) · 733 Bytes
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
require('dotenv').config();
const axios = require('axios');
const fs = require('fs');
const API_KEY = process.env.API_KEY;
const API_URL =
'https://opendata.uta.fi:8443/apiman-gateway/UTA/opintojaksot/1.0';
axios.defaults.headers.get['X-API-key'] = API_KEY;
const getCourses = async () => {
try {
const response = await axios.get(API_URL);
const data = await response.data;
// TODO: validate data before writing
fs.writeFile('./courses.json', JSON.stringify(data), err => {
if (err) throw Error(err);
});
} catch (e) {
throw Error(e);
}
};
console.info('\n\nUpdating courses...\n\n');
getCourses()
.then(() => console.info('\n\nCourses updated!\n\n'))
.catch(err => console.error(err));