8
8
const MongoClient = require ( 'mongodb' ) ;
9
9
const request = require ( 'request-promise-native' ) . defaults ( { jar : true } ) ;
10
10
11
- const sleep = ms => {
12
- return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
13
- } ;
14
-
15
11
// Using an async foreach so we can use request promises in each payload
16
12
async function asyncForEach ( array , callback ) {
17
13
for ( let index = 0 ; index < array . length ; index += 1 ) {
@@ -52,31 +48,34 @@ async function asyncForEach(array, callback) {
52
48
} ) ;
53
49
54
50
const start = async ( ) => {
51
+ try {
52
+ orbitData = await request ( 'https://www.space-track.org/basicspacedata/query/class/tle_latest/ORDINAL/1/orderby/NORAD_CAT_ID/epoch/>now-30/format/json' ) ;
53
+ } catch ( e ) {
54
+ console . log ( 'Login Broken' ) ;
55
+ process . exit ( 1 ) ;
56
+ }
57
+ const orbit = JSON . parse ( orbitData ) ;
58
+
55
59
await asyncForEach ( id , async num => {
56
- await sleep ( 7000 ) ;
57
- try {
58
- orbitData = await request ( `https://www.space-track.org/basicspacedata/query/class/tle/NORAD_CAT_ID/${ num } /limit/1` ) ;
59
- } catch ( e ) {
60
- console . log ( 'Login Broken' ) ;
61
- process . exit ( 1 ) ;
62
- }
63
- const orbit = JSON . parse ( orbitData ) ;
60
+ const specific_orbit = orbit . filter ( satellite => {
61
+ return parseInt ( satellite . NORAD_CAT_ID , 10 ) === num ;
62
+ } ) ;
64
63
65
- if ( orbit [ 0 ] !== undefined && orbit . length !== 0 ) {
64
+ if ( specific_orbit [ 0 ] !== undefined && specific_orbit . length !== 0 ) {
66
65
const update = {
67
- epoch : new Date ( orbit [ 0 ] . EPOCH ) . toISOString ( ) ,
68
- mean_motion : parseFloat ( orbit [ 0 ] . MEAN_MOTION ) ,
69
- raan : parseFloat ( orbit [ 0 ] . RA_OF_ASC_NODE ) ,
70
- arg_of_pericenter : parseFloat ( orbit [ 0 ] . ARG_OF_PERICENTER ) ,
71
- mean_anomaly : parseFloat ( orbit [ 0 ] . MEAN_ANOMALY ) ,
72
- semi_major_axis_km : parseFloat ( orbit [ 0 ] . SEMIMAJOR_AXIS ) ,
73
- eccentricity : parseFloat ( orbit [ 0 ] . ECCENTRICITY ) ,
74
- periapsis_km : parseFloat ( orbit [ 0 ] . PERIGEE ) ,
75
- apoapsis_km : parseFloat ( orbit [ 0 ] . APOGEE ) ,
76
- inclination_deg : parseFloat ( orbit [ 0 ] . INCLINATION ) ,
77
- period_min : parseFloat ( orbit [ 0 ] . PERIOD ) ,
66
+ epoch : new Date ( specific_orbit [ 0 ] . EPOCH ) . toISOString ( ) ,
67
+ mean_motion : parseFloat ( specific_orbit [ 0 ] . MEAN_MOTION ) ,
68
+ raan : parseFloat ( specific_orbit [ 0 ] . RA_OF_ASC_NODE ) ,
69
+ arg_of_pericenter : parseFloat ( specific_orbit [ 0 ] . ARG_OF_PERICENTER ) ,
70
+ mean_anomaly : parseFloat ( specific_orbit [ 0 ] . MEAN_ANOMALY ) ,
71
+ semi_major_axis_km : parseFloat ( specific_orbit [ 0 ] . SEMIMAJOR_AXIS ) ,
72
+ eccentricity : parseFloat ( specific_orbit [ 0 ] . ECCENTRICITY ) ,
73
+ periapsis_km : parseFloat ( specific_orbit [ 0 ] . PERIGEE ) ,
74
+ apoapsis_km : parseFloat ( specific_orbit [ 0 ] . APOGEE ) ,
75
+ inclination_deg : parseFloat ( specific_orbit [ 0 ] . INCLINATION ) ,
76
+ period_min : parseFloat ( specific_orbit [ 0 ] . PERIOD ) ,
78
77
} ;
79
- console . log ( `Updating...${ orbit [ 0 ] . OBJECT_NAME } ` ) ;
78
+ console . log ( `Updating...${ specific_orbit [ 0 ] . OBJECT_NAME } ` ) ;
80
79
console . log ( update ) ;
81
80
await col . updateOne ( { 'rocket.second_stage.payloads.norad_id' : num } , {
82
81
$set : {
@@ -93,7 +92,6 @@ async function asyncForEach(array, callback) {
93
92
'rocket.second_stage.payloads.$.orbit_params.period_min' : update . period_min ,
94
93
} ,
95
94
} ) ;
96
- console . log ( 'Updated...' ) ;
97
95
}
98
96
} ) ;
99
97
} ;
0 commit comments