Skip to content

Commit

Permalink
Add missions updating to ships update script
Browse files Browse the repository at this point in the history
  • Loading branch information
jakewmeyer committed Nov 17, 2018
1 parent 2950b4d commit 566e9ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 0 additions & 1 deletion scripts/landpad.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const MongoClient = require('mongodb');
console.log(`Sucesses: ${asog_successes}\n`);

const landpad = client.db('spacex-api').collection('landpad');

await landpad.updateOne({ id: 'LZ-1' }, { $set: { attempted_landings: lz1_attempts, successful_landings: lz1_successes } });
await landpad.updateOne({ id: 'LZ-2' }, { $set: { attempted_landings: lz2_attempts, successful_landings: lz2_successes } });
await landpad.updateOne({ id: 'LZ-4' }, { $set: { attempted_landings: lz4_attempts, successful_landings: lz4_successes } });
Expand Down
22 changes: 22 additions & 0 deletions scripts/ships.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ async function asyncForEach(array, callback) {

// Gather individual ship mmsi numbers into array for requests
const id = [];
const names = [];
await data.forEach(ship => {
if (ship.mmsi != null) {
id.push(ship.mmsi);
}
names.push(ship.ship_id);
});

const start = async () => {
Expand Down Expand Up @@ -92,7 +94,27 @@ async function asyncForEach(array, callback) {
await sleep(5000);
});
};
const finish = async () => {
await asyncForEach(names, async name => {
const missions = [];
const launches = client.db('spacex-api').collection('launch');
const launch_results = await launches.find({ upcoming: false, ships: name }).project({ _id: 0, flight_number: 1, mission_name: 1 }).sort({ flight_number: 1 }).toArray();

launch_results.forEach(launch => {
const mission = {
name: launch.mission_name,
flight: launch.flight_number,
};
missions.push(mission);
});
console.log(name);
console.log(missions);

await col.updateOne({ ship_id: name }, { $set: { missions } });
});
};
await start();
await finish();
console.log(`Updated ${id.length} ships`);

if (client) {
Expand Down

0 comments on commit 566e9ad

Please sign in to comment.