-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
118 lines (88 loc) · 3.13 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const fs = require('fs');
const express = require('express');
const outlooks = new (require('./lib/outlooks.js'));
const cyclones = new (require('./lib/cyclones.js'));
const app = express();
const port = 8484;
outlooks.functions.init();
cyclones.functions.init();
var json;
var jsonHurricanes;
var jsonTropicalStorms;
var jsonTropicalDepressions;
var jsonOutlooks;
async function loadApi() {
const atlanticOutlook = await outlooks.functions.getAtlanticOutlook();
const eastPacificOutlook = await outlooks.functions.getEastPacificOutlook();
const centralPacificOutlook = await outlooks.functions.getCentralPacificOutlook();
const activeStorms = await cyclones.functions.getAllStorms();
json = {
outlooks: {
atlanticOutlook: atlanticOutlook,
eastPacificOutlook: eastPacificOutlook,
centralPacificOutlook: centralPacificOutlook
},
activeStorms
}
fs.writeFileSync('index.json', JSON.stringify(json, null, 2));
}
loadApi();
async function loadHurricanes() {
const activeHurricanes = await cyclones.functions.getHurricanes();
jsonHurricanes = {
activeHurricanes
}
fs.writeFileSync('hurricanes.json', JSON.stringify(jsonHurricanes, null, 2));
}
loadHurricanes();
async function loadTropicalStorms() {
const activeStorms = await cyclones.functions.getTropicalStorms();
jsonTropicalStorms = {
activeStorms
}
fs.writeFileSync('tropical-storms.json', JSON.stringify(jsonTropicalStorms, null, 2));
}
loadTropicalStorms();
async function loadTropicalDepressions() {
const activeDepressions = await cyclones.functions.getTropicalDepressions();
const potentialCyclones = await cyclones.functions.getPotentialCyclones();
jsonTropicalDepressions = {
activeDepressions: activeDepressions,
potentialCyclones: potentialCyclones
}
fs.writeFileSync('tropical-depressions.json', JSON.stringify(jsonTropicalDepressions, null, 2));
}
loadTropicalDepressions();
async function loadOutlooks() {
const atlanticOutlook = await outlooks.functions.getAtlanticOutlook();
const eastPacificOutlook = await outlooks.functions.getEastPacificOutlook();
const centralPacificOutlook = await outlooks.functions.getCentralPacificOutlook();
jsonOutlooks = {
outlooks: {
atlanticOutlook: atlanticOutlook,
eastPacificOutlook: eastPacificOutlook,
centralPacificOutlook: centralPacificOutlook
}
}
fs.writeFileSync('outlooks.json', JSON.stringify(jsonOutlooks, null, 2));
}
loadOutlooks();
// De-note when testing
// app.get('/index.json', async (req, res) => {
// res.json(json);
// })
// app.get('/hurricanes.json', async (req, res) => {
// res.json(jsonHurricanes);
// })
// app.get('/tropical-storms.json', async (req, res) => {
// res.json(jsonTropicalStorms);
// })
// app.get('/tropical-depressions.json', async (req, res) => {
// res.json(jsonTropicalDepressions);
// })
// app.get('/outlooks.json', async (req, res) => {
// res.json(jsonOutlooks);
// })
// app.listen(port, () => {
// console.log(`Listening on port ${port}`);
// })