Skip to content

Commit 0424e03

Browse files
authored
Merge pull request #592 from buster95/feature/docker
[Docker] Phase 1: Splitting scraper from API
2 parents b31461e + 5f0f392 commit 0424e03

File tree

15 files changed

+68
-39
lines changed

15 files changed

+68
-39
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
name: Eslint
22
on:
33
push:
4-
branches: [ master ]
4+
branches: [master]
55
pull_request:
6-
branches: [ master ]
6+
branches: [master]
77
jobs:
88
eslint:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v2
1212
- run: npm install
1313
- run: npm run lint
14-

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
pull_request:
66
branches: [master]
77
schedule:
8-
- cron: '0 */2 * * *'
8+
- cron: "0 */2 * * *"
99
jobs:
1010
unittests:
1111
runs-on: ubuntu-latest
@@ -15,6 +15,9 @@ jobs:
1515
steps:
1616
- name: Git checkout
1717
uses: actions/checkout@v2
18+
- uses: zcong1993/setup-timezone@master
19+
with:
20+
timezone: America/Denver
1821
- name: Start redis server
1922
uses: supercharge/redis-github-action@1.1.0
2023
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ node_modules/
22
json.sqlite
33
.vscode/
44
config.json
5+
docker.env
56
package-lock.json
67
dump.rdb
78
yarn.lock

.mocharc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
file: ['./tests/mochaSetup.spec.js']
3+
};

config/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const keys = require('./config.keys.json');
2+
let config;
3+
4+
try {
5+
config = require('./config.json');
6+
} catch (err) {
7+
config = require('./config.example.json');
8+
}
9+
10+
console.log(process.env.covid_api_mode);
11+
12+
module.exports = {
13+
config,
14+
keys
15+
};

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
],
1818
"scripts": {
1919
"start": "node server.js",
20+
"start:scraper": "node server_scraper.js",
2021
"start:dev": "nodemon --watch routes --watch scrapers --watch utils ./server.js ",
2122
"lint": "eslint '**/*.js' --ignore-pattern node_modules/",
2223
"lint:fix": "eslint ./**/*.js --fix --ignore-pattern node_modules/",
2324
"lint:win32": "eslint ./**/*.js --ignore-pattern node_modules/",
24-
"test": "mocha ./tests --exit --timeout 50000"
25+
"test": "mocha ./tests --exit --timeout 60000",
26+
"docker-start": "docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build",
27+
"docker-test": "docker-compose -f docker-compose.yml -f docker-compose.test.yml up --abort-on-container-exit --build"
2528
},
2629
"dependencies": {
2730
"@sentry/node": "5.12.2",
@@ -45,4 +48,4 @@
4548
"mocha": "^7.1.1",
4649
"nodemon": "^2.0.2"
4750
}
48-
}
51+
}

routes/instances.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,15 @@
22
const Redis = require('ioredis');
33

44
// LOCAL FUNCTIONS
5+
const logger = require('../utils/logger');
56
const getWorldometerPage = require('../scrapers/getWorldometers');
67
const getStates = require('../scrapers/getStates');
78
const jhuLocations = require('../scrapers/jhuLocations');
89
const historical = require('../scrapers/historical');
910
const nytData = require('../scrapers/nytData');
1011

1112
// KEYS
12-
const keys = require('../config.keys.json');
13-
14-
let config;
15-
try {
16-
config = require('../config.json');
17-
} catch (err) {
18-
config = require('../config.example.json');
19-
}
13+
const { config, keys } = require('../config');
2014

2115
const redis = new Redis(config.redis.host, {
2216
password: config.redis.password,
@@ -32,6 +26,20 @@ module.exports = {
3226
getStates,
3327
jhuLocations,
3428
historical,
35-
nytData
29+
nytData,
30+
executeScraper: async () => {
31+
await Promise.all([
32+
getWorldometerPage(keys, redis),
33+
getStates(keys, redis),
34+
jhuLocations.jhudataV2(keys, redis),
35+
historical.historicalV2(keys, redis),
36+
historical.getHistoricalUSADataV2(keys, redis)
37+
]);
38+
logger.info('Finished scraping!');
39+
},
40+
executeScraperNYTData: async () => {
41+
await nytData(keys, redis);
42+
logger.info('Finished NYT scraping!');
43+
}
3644
}
3745
};

scrapers/getStates.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const getStates = async (keys, redis) => {
7575
response = await axios.get('https://www.worldometers.info/coronavirus/country/us/');
7676
} catch (err) {
7777
logger.err('Error: Requesting GetStates failed!', err);
78+
return;
7879
}
7980
const html = cheerio.load(response.data);
8081

0 commit comments

Comments
 (0)