-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.js
More file actions
45 lines (32 loc) · 1.03 KB
/
handler.js
File metadata and controls
45 lines (32 loc) · 1.03 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
38
39
40
41
'use strict';
const request = require("axios");
const {extractData} = require('./helpers');
let firebase = require('firebase');
module.exports.getsatcatboxscore = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
let config = {
apiKey: "AIzaSyDzP86erCckOKENIaFTqR0MpxZwG-VJbhY",
authDomain: "satcatparser.firebaseapp.com",
databaseURL: "https://satcatparser.firebaseio.com",
projectId: "satcatparser",
storageBucket: "satcatparser.appspot.com",
messagingSenderId: "90035590416"
};
if(firebase.apps.length === 0) { // <---Important!!! In lambda, it will cause double initialization.
firebase.initializeApp(config);
}
let satData;
request('https://www.celestrak.com/satcat/boxscore.asp')
.then(({data}) => {
satData = extractData(data);
})
.then(response => {
firebase.database().ref().child('data').set(satData, function(){
process.exit(0);
})
})
.then(() => {
callback(null, 'END');
})
.catch(callback);
};