-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
144 lines (102 loc) · 3.32 KB
/
app.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
require('dotenv').config();
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
const _ = require('lodash');
const mongoose = require('mongoose');
const https = require("https");
let Id = [];
Id["CODEFORCES"] = 1;
Id["CODECHEF"] = 2;
Id["HACKEREARTH"] = 73;
Id["HACKERRANK"] = 63;
Id["LEETCODE"] = 102;
Id["TOPCODER"] = 12;
Id["SPOJ"] = 26;
Id["FACEBOOK"] = 29;
Id["GOOGLE"] = 35;
Id["ATCODER"] = 93;
let Array = [];
const app = express();
app.use(express.static("public"));
app.set('view engine', 'ejs');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));
app.get("/", function (req, res) {
res.render("home");
});
// console.log(process.env.USERNAM);
// console.log(process.env.API_KEY);
//console.log(process.env.GOOGLE_ID);
app.get("/:platform", function (req, res) {
console.log(req.params.platform);
res.render("time", { platform: req.params.platform});
});
app.get("/:platform/:time", function (req, res) {
console.log(req.params.time);
});
app.post("/contest", function (req, res) {
let num = req.body.num1;
let length = num.length;
let s1 = num.substring(length - 3, length);
// console.log(s1);
let s2 = num.substring(0, length - 3).toUpperCase();
let s3 = num.substring(0, length - 3)
console.log(Id[s2]);
const apiKey = `username=${process.env.USERNAM}&api_key=${process.env.API_KEY}`;
var m = new Date();
var dateString = m.getFullYear() + "-" + (m.getMonth() + 1) + "-" + m.getDate() + "T" + m.getHours() + ":" + m.getMinutes() + ":" + m.getSeconds();
var pastString = (m.getFullYear() - 1) + "-" + (m.getMonth() + 1) + "-" + m.getDate() + "T" + m.getHours() + ":" + m.getMinutes() + ":" + m.getSeconds();
let url;
let time;
if (s1 === "liv") {
url = `https://clist.by:443/api/v1/json/contest/?resource__id=${Id[s2]}&end__gte=${dateString}&start__lte=${dateString}&order_by=id&${apiKey}`;
time = "live";
}
else if (s1 === "pas") {
url = `https://clist.by:443/api/v1/json/contest/?resource__id=${Id[s2]}&start__gte=${pastString}&end__lt=${dateString}&order_by=-start&${apiKey}&limit=30`;
time = "past";
}
else if (s1 === "fut") {
url = `https://clist.by:443/api/v1/json/contest/?resource__id=${Id[s2]}&start__gte=${dateString}&order_by=id&${apiKey}&limit=30`;
time = "future";
}
// console.log(url);
// console.log(apiKey);
https.get(url, function (response) {
console.log(response.statusCode);
var temp = [];
let stockData = "";
response.on("data", function (data) {
stockData += data;
});
response.on("end", function () {
let contestInfo = JSON.parse(stockData)
console.log(contestInfo);
temp = contestInfo.objects;
// res.write(temp);
// console.log(dateString);
console.log(temp);
if(temp.length===0){
res.render("error" , {platform : s3 , time : time});
}
else{
res.render("contest" , {
platform : s3,
contestArray : temp,
time : time
});
}
});
});
});
app.post("/team", function (req, res) {
let buttons = req.body.button;
if(buttons==="second")
res.render("team");
else
res.render("contact");
});
app.listen(3000, function () {
console.log("Server started on port 3000");
});