-
Notifications
You must be signed in to change notification settings - Fork 0
/
populator.js
67 lines (52 loc) · 3.81 KB
/
populator.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
const Firestore = require('@google-cloud/firestore');
const firestore = new Firestore({
projectId: 'find-dining-d29f5',
keyFilename: './Find Dining-2f1d94f5e21c.json',
});
const fetch = require("node-fetch");
var parser = require('xml2json');
async function populate() {
const uniqueMeals = new Set();
const document = await firestore.collection('offerings');
const mealDoc = await firestore.collection("meals");
for (let i = 4; i <= 100; i++) {
const url = `https://microsoft.sharepoint.com/sites/refweb/_api/web/lists/GetByTitle('DiningMenus')/items?$select=CafeName,StationName,DayOfWeekID,WeekDate,MenuItem,MenuDescription,MenuPrice&$filter=CafeName%20eq%20%27Cafe%20${i}%27%20and%20WeekDate%20ge%20datetime%272018-07-23T07:00:00.000Z%27%20and%20WeekDate%20le%20datetime%272018-07-24T06:59:59.059Z%27&$orderby=DayOfWeekID,StationName&$top=700`;
const cafename = `Cafe ${i}`;
let resp;
try {
resp = await fetch(url, {
headers: {
cookie: 'SearchSession=6f13f001%2Dd77a%2D43f7%2D8b15%2Da0a2a3f9de6f; rtFa=80N8vfIlC40wfznkrPCYYW3ulSFR3Q5q7WNjxH4N6PYmRUM2M0IwOUItOTc0OC00N0JBLTkwMTgtQkVFQURENDA1MjA0TTskNI2S5t0Lh9UDocKL9f8lkp+yhwijsuAbI3xDVJkT8Ll1mNHR76dLNd8ipRoFnDM7i8SAU2Q8ZVot63VPABea3gpYNJtrNIy7t9RbFGiDjc2CrS37CgZd90QG8lM/H7hj0JfX3DW81DpH7Ko27UAg36YIkrkq2jeku0+xkCbK074Trxk+H6zI+nRtS17wXj/6skmjRqGjHEQjCdefHBnMTkX9ebHrbEx8Hp5sgRpljRO/zwAYNyJj1yUrWvawI05US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anBBPT08L1NQPg==; ai_user=h0Ugi|2018-07-23T22:14:05.827Z; WSS_FullScreenMode=false; odbn=1; ec63b09b974847ba9018beeadd405204c47526217f8f480484203449e6dbd0b7i%3A0%23%2Ef%7Cmembership%7Cshwsha%40microsoft%2Ecom=0; WT_FPC=id=0dc25663-214c-4398-8bec-dc907651d42c:lv=1532381267837:ss=1532380447300; ai_session=7MfoU|1532384046221|1532384911344.7'
}
});
} catch (e) {
continue;
}
const xml = await resp.text();
const data = JSON.parse(parser.toJson(xml));
if (!data.feed || !data.feed.entry) { continue; }
data.feed.entry.forEach(async (entry) => {
const meal = entry.content['m:properties']['d:MenuItem'];
uniqueMeals.add(meal);
const day = entry.content['m:properties']['d:DayOfWeekID']['$t'];
try {
const offering = {
cafename,
day,
meal
};
console.log("Offering" + offering.meal);
await document.add(offering);
const meals = {
meal
}
if (typeof meal == "string" ) {
await mealDoc.add(meals);
}
} catch(e) {
console.log('FAIL', e);
}
});
}
}
populate();