COVID-19 Czech Reproduction number
DeprecatedView all Actors
This Actor is unavailable because the developer has decided to deprecate it. Would you like to try a similar Actor instead?
See alternative ActorsCOVID-19 Czech Reproduction number
sablatura/covid-r0-czech
COVID-19 Reproduction number estimate in the Czech Republic since the SARS-CoV-2 outbreak started. Processed every hour, history is shown per day.
Dockerfile
1# Dockerfile contains instructions how to build a Docker image that
2# will contain all the code and configuration needed to run your actor.
3# For a full Dockerfile reference,
4# see https://docs.docker.com/engine/reference/builder/
5
6# First, specify the base Docker image. Apify provides the following
7# base images for your convenience:
8# apify/actor-node-basic (Node.js on Alpine Linux, small and fast)
9# apify/actor-node-chrome (Node.js + Chrome on Debian)
10# apify/actor-node-chrome-xvfb (Node.js + Chrome + Xvfb on Debian)
11# For more information, see https://docs.apify.com/actor/build#base-images
12# Note that you can use any other image from Docker Hub.
13FROM apify/actor-node-chrome
14
15# Second, copy just package.json since it should be the only file
16# that affects "npm install" in the next step, to speed up the build
17COPY package.json ./
18
19# Install NPM packages, skip optional and development dependencies to
20# keep the image small. Avoid logging too much and print the dependency
21# tree for debugging
22RUN npm --quiet set progress=false \
23 && npm install --only=prod --no-optional \
24 && echo "Installed NPM packages:" \
25 && npm list || true \
26 && echo "Node.js version:" \
27 && node --version \
28 && echo "NPM version:" \
29 && npm --version
30
31# Next, copy the remaining files and directories with the source code.
32# Since we do this after NPM install, quick build will be really fast
33# for most source file changes.
34COPY . ./
35
36# Optionally, specify how to launch the source code of your actor.
37# By default, Apify's base Docker images define the CMD instruction
38# that runs the Node.js source code using the command specified
39# in the "scripts.start" section of the package.json file.
40# In short, the instruction looks something like this:
41#
42# CMD npm start
main.js
1const Apify = require('apify');
2const { google } = require('googleapis');
3const { apifyGoogleAuth } = require('apify-google-auth');
4
5Apify.main(async () => {
6 const input = await Apify.getInput();
7 //console.log('My input:');
8 //console.dir(input);
9
10 const {client_secret, client_id} = input.googleCredentials;
11 const {APIFY_CONTAINER_PORT, APIFY_CONTAINER_URL, APIFY_DEFAULT_KEY_VALUE_STORE_ID,} = process.env;
12 const redirect_uri = APIFY_CONTAINER_URL;
13
14 const authOptions = {
15 scope: 'spreadsheets',
16 tokensStore: 'covid-spreadsheet-token',
17 credentials: {
18 client_id: client_id,
19 client_secret: client_secret,
20 redirect_uri: redirect_uri,
21 },
22 };
23
24 // Checks your tokensStore for token first. If not found, prompts you to authorize.
25 const authClient = await apifyGoogleAuth(authOptions);
26
27 const sheets = google.sheets({ version: 'v4', auth: authClient });
28
29 const params = {
30 // The ID of the spreadsheet to retrieve data from.
31 spreadsheetId: '1cCCECunGrLmcxp5RwTRvHPLPi2Uh2J8b4NIoyFDcu7c', // TODO: Update placeholder value.
32
33 // The A1 notation of the values to retrieve.
34 range: 'A2:D1000', // TODO: Update placeholder value.
35
36 // How values should be represented in the output.
37 // The default render option is ValueRenderOption.FORMATTED_VALUE.
38 //valueRenderOption: '', // TODO: Update placeholder value.
39
40 // How dates, times, and durations should be represented in the output.
41 // This is ignored if value_render_option is
42 // FORMATTED_VALUE.
43 // The default dateTime render option is [DateTimeRenderOption.SERIAL_NUMBER].
44 //dateTimeRenderOption: '', // TODO: Update placeholder value.
45 };
46
47 //console.log("testing spreasheets");
48 const request = await sheets.spreadsheets.values.get(params);
49 //console.log(request.data);
50
51 let data = request.data.values;
52 let ordered = [];
53
54 for (var i = 0; i < request.data.values.length; i++) {
55 const row = request.data.values[i];
56 const date = row[0];
57 const mid = parseFloat(row[1]);
58 const low = parseFloat(row[2]);
59 const max = parseFloat(row[3]);
60 ordered[i] = [];
61 ordered[i][0] = date;
62 ordered[i][1] = low;
63 ordered[i][2] = mid;
64 ordered[i][3] = max;
65 }
66
67 data = ordered;
68
69 // And then save output
70 let output = {
71 data,
72 "lastUpdatedAtSource": new Date(),
73 "lastUpdatedAtApify": new Date(),
74 "readMe": "https://www.sablatura.info/covid/api",
75 //crawledAt: new Date(),
76 };
77
78 const { keyValueStores } = Apify.client;
79
80 const { id: storeId } = await keyValueStores.getOrCreateStore({
81 storeName: 'COVID-CZ-R0'
82 });
83
84 Apify.client.setOptions({ storeId });
85
86 //output = JSON.stringify(output);
87 //console.log('My output:');
88 //console.dir(output);
89 await Apify.setValue('OUTPUT', output);
90
91 // Just pass the 'key' as the 'keyValueStores' already knows
92 // in what 'storeId' to look at.
93 const record = await keyValueStores.getRecord({ key: 'LATEST' });
94
95 // Check for empty 'STATE' records
96 const storeRecord = record && record.body ? record.body : {};
97
98 const previousState = typeof storeRecord === 'string' ?
99 JSON.parse(storeRecord) : storeRecord;
100
101 // It is a good practice to copy objects instead of
102 // overwriting them. Weird things can happen otherwise.
103 const nextState = Object.assign({}, previousState, output);
104
105 await keyValueStores.putRecord({
106 key: 'LATEST',
107 body: JSON.stringify(nextState),
108 });
109
110});
package.json
1{
2 "name": "covid-R0-czech",
3 "version": "0.0.2",
4 "dependencies": {
5 "apify": "^0.20.2",
6 "googleapis": "48.0.0",
7 "apify-google-auth": "0.3.0"
8 },
9 "scripts": {
10 "start": "node main.js"
11 },
12 "author": "Jan Šablatura"
13}
Developer
Maintained by Community
Categories