-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (48 loc) · 1.61 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
'use strict';
const fs = require('fs');
const _ = require('lodash');
const request = require('request-promise');
const ProductsIndex = require('./products_index');
const SuggestionsIndex = require('./suggestions_index');
const pubDemoDataIndexer = require('./indexers/pub_demo_data_indexer');
const bestBuyIndexer = require('./indexers/best_buy_indexer');
const wallmartIndexer = require('./indexers/wallmart_indexer');
const apiBaseUrl = 'https://api.bigwednesday.io/1';
const productsIndex = new ProductsIndex(apiBaseUrl, '8N*b3i[EX[s*zQ%');
const suggestionsIndex = new SuggestionsIndex(apiBaseUrl, '8N*b3i[EX[s*zQ%');
console.log('Deleting existing indexes');
Promise.all([
suggestionsIndex.delete(),
productsIndex.delete()
])
.then(() => {
console.log('Recreating indexes');
return Promise.all([
suggestionsIndex.create(),
productsIndex.create()
]);
})
.then(() => {
console.log('Getting categories');
return request({uri: 'https://raw.githubusercontent.com/BigWednesdayIO/categories-api/master/categories.json', json: true})
.then(categories => {
fs.writeFileSync('./categories.json', JSON.stringify(categories));
});
})
.then(() => {
console.log('Indexing pub demo data');
return pubDemoDataIndexer(productsIndex, suggestionsIndex);
})
.then(() => {
console.log('Indexing Best Buy data');
return bestBuyIndexer(productsIndex, suggestionsIndex);
})
.then(() => {
console.log('Indexing Wallmart data');
return wallmartIndexer(productsIndex, suggestionsIndex);
})
.catch(err => {
console.error('Error. Aborting.');
console.error(err);
process.exit(1);
});