Skip to content

Commit ee00134

Browse files
Convert to AWS Lambda
1 parent 84ead19 commit ee00134

File tree

6 files changed

+70
-203
lines changed

6 files changed

+70
-203
lines changed

package.json

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
"version": "1.0.0",
44
"description": "An API listing programming contests across multiple platforms",
55
"main": "index.js",
6-
"scripts": {
7-
"start": "node src/app.js",
8-
"test": "mocha --timeout 30000"
9-
},
6+
"scripts": {},
107
"repository": {
118
"type": "git",
129
"url": "git+https://github.com/nishanthvijayan/programming-contests-api.git"
@@ -18,14 +15,11 @@
1815
},
1916
"homepage": "https://github.com/nishanthvijayan/programming-contests-api#readme",
2017
"dependencies": {
18+
"aws-sdk": "^2.809.0",
2119
"axios": "^0.19.0",
22-
"cheerio": "^1.0.0-rc.2",
23-
"cron": "^1.4.0",
24-
"memory-cache": "^0.2.0"
20+
"cheerio": "^1.0.0-rc.2"
2521
},
2622
"devDependencies": {
27-
"chai": "^4.0.2",
28-
"chai-http": "^3.0.0",
2923
"eslint": "^5.3.0",
3024
"eslint-config-airbnb-base": "^13.1.0",
3125
"eslint-plugin-import": "^2.14.0",

src/app.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/index.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
const AWS = require('aws-sdk');
2+
const axios = require('axios');
3+
4+
const { flat, getCurrentTimeInSeconds } = require('./utils');
5+
6+
const codeforces = require('./parsers/codeforces');
7+
const hackerearth = require('./parsers/hackerearth');
8+
const hackerrank = require('./parsers/hackerrank');
9+
const topcoder = require('./parsers/topcoder');
10+
const leetcode = require('./parsers/leetcode');
11+
const codechef = require('./parsers/codechef');
12+
const atcoder = require('./parsers/atcoder');
13+
const csacademy = require('./parsers/csacademy');
14+
const coj = require('./parsers/coj');
15+
const kaggle = require('./parsers/kaggle');
16+
17+
const s3bucket = new AWS.S3({});
18+
19+
20+
exports.handler = async (event) => {
21+
return axios.all([
22+
codeforces(),
23+
hackerearth(),
24+
hackerrank(),
25+
topcoder(),
26+
leetcode(),
27+
codechef(),
28+
atcoder(),
29+
csacademy(),
30+
coj(),
31+
kaggle(),
32+
])
33+
.then((contestsByPlatform) => {
34+
const contests = flat(contestsByPlatform.filter(it => Array.isArray(it)));
35+
36+
const curTime = getCurrentTimeInSeconds();
37+
38+
const sortByStartTime = (a, b) => a.startTime - b.startTime;
39+
const sortByEndTime = (a, b) => a.endTime - b.endTime;
40+
41+
const isOngoing = contest => contest.startTime < curTime && contest.endTime > curTime;
42+
const isUpcoming = contest => contest.startTime > curTime && contest.endTime > curTime;
43+
44+
const ongoingContests = contests.filter(isOngoing).sort(sortByEndTime);
45+
const upcomingContests = contests.filter(isUpcoming).sort(sortByStartTime);
46+
47+
const contestsJson = JSON.stringify({
48+
timestamp: curTime,
49+
ongoing: ongoingContests,
50+
upcoming: upcomingContests,
51+
});
52+
53+
const params = {
54+
Bucket: "codercalendar-api",
55+
Key: "response.json",
56+
Body: contestsJson,
57+
ContentType: "application/json;charset=UTF-8",
58+
ACL: 'public-read'
59+
};
60+
61+
return s3bucket.upload(params).promise().then((data) => {
62+
console.log(`File uploaded successfully at ${data.Location}`)
63+
});
64+
});
65+
};
66+
67+

src/runner.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/server.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

test/filter.js

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy