Skip to content

Commit ce66ea0

Browse files
authored
Merge pull request #264 from Minimini20/master
Automatic Codeforces contest notifier
2 parents 69e3231 + d385842 commit ce66ea0

File tree

3 files changed

+190
-144
lines changed

3 files changed

+190
-144
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
// CodeForces - Contest Notifier: This tool first logs in to your CodeForces id and then registers to all the contests available at the moment for you.
2+
// It also scrapes the already registered and upcoming contests' data and notifies you of the dates and time of all contests through a text via Whatsapp Web.
3+
// Tech-Stacks : JavaScript, HTML, CSS, puppeteer
4+
5+
const pup = require("puppeteer");
6+
let fs = require('fs');
7+
let email = ""; //type in your email and password to use automatic contest notifier
8+
let password = "";
9+
let url = "https://codeforces.com/";
10+
async function main(){
11+
let browser = await pup.launch({ // opens the browser
12+
headless: false,
13+
defaultViewport: false,
14+
args: ["--start-maximized"]// fullscreen
15+
});
16+
let pages = await browser.pages();// browser ke andar opened tabs ko ek array mien leke aana
17+
tab = pages[0];
18+
await tab.goto(url);
19+
await tab.waitForSelector(".menu-list.main-menu-list",{visible:true});// wait for a css selector to load on page
20+
let list = await tab.$$(".menu-list.main-menu-list li a");
21+
let contest = list[2];
22+
let contestUrl = await tab.evaluate(function(ele){
23+
return ele.getAttribute("href");
24+
},contest);
25+
await tab.goto("https://codeforces.com"+contestUrl);// goes to codeforces main site
26+
await tab.waitForSelector(".lang-chooser",{visible:true,setTimeout:2000});
27+
let enterRegister = await tab.$$(".lang-chooser a");
28+
let enter = enterRegister[2];
29+
let enterHref = await tab.evaluate(function(ele){
30+
return ele.getAttribute("href"); // gets hyperlink address
31+
},enter);
32+
await tab.goto("https://codeforces.com"+enterHref);
33+
await tab.waitForSelector("#handleOrEmail",{visible:true,setTimeout:2000});
34+
await tab.type("#handleOrEmail",email); // types in email password asynchronusly
35+
await tab.type("#password",password);
36+
await tab.click("input[value='Login']");
37+
await tab.waitForSelector("div[style='background-color: white;margin:0.3em 3px 0 3px;position:relative;']",{visible:true,setTimeout:2000});
38+
let tables = await tab.$$("div[style='background-color: white;margin:0.3em 3px 0 3px;position:relative;'] table");
39+
//console.log(tables.length);
40+
let rows = await tables[0].$$("tr");
41+
//console.log(rows.length);
42+
let remindDates = [];
43+
let registerUrls = [];
44+
for(let i=1;i<rows.length;i++){
45+
let columns = await rows[i].$$("td");
46+
let aTagCount = await columns[columns.length-1].$$("a");
47+
if(aTagCount.length==2){
48+
let hrefCalc = await tab.evaluate(function(ele){
49+
return ele.getAttribute("href");
50+
},aTagCount[0]);
51+
registerUrls.push("https://codeforces.com"+hrefCalc);
52+
}
53+
else{
54+
//creating data of contests and their timings
55+
let data = {};
56+
let text = await columns[columns.length-2].$(".countdown");
57+
let innerText = await tab.evaluate(function(ele){
58+
return ele.textContent;
59+
},text);
60+
let nameOfContest = await tab.evaluate(function(ele){
61+
return ele.textContent;
62+
},columns[0]);
63+
let timeValue = await columns[2].$("a");
64+
let time =await tab.evaluate(function(ele){
65+
return ele.textContent;
66+
},timeValue)
67+
data["Name"]=nameOfContest;
68+
let today = new Date();
69+
let day = parseInt(today.getDate());
70+
let month = parseInt(today.getMonth());
71+
month++;
72+
if(month<10){
73+
month="0"+month;
74+
}
75+
//extracting date time etc. from the contest timeline
76+
if(innerText.includes("days")|| innerText.includes("day")){
77+
let numberOfDaysToAdd = parseInt(innerText.split(" ")[0]) ;
78+
//console.log(numberOfDaysToAdd);
79+
//console.log(day +" "+ month);
80+
let finalDay = parseInt(day+numberOfDaysToAdd);
81+
if(month == "02"){
82+
if(finalDay>28){
83+
finalDay = finalDay - 28;
84+
month = parseInt("03");
85+
}
86+
}
87+
else if(month =="04"||month=="06"||month=="09"||month=="11"){
88+
if(finalDay>30){
89+
finalDay = finalDay-30;
90+
month = parseInt(month)+1;
91+
}
92+
}
93+
else{
94+
if(finalDay>31){
95+
finalDay = finalDay - 31;
96+
month = parseInt(month)+1;
97+
}
98+
}
99+
let dateOfContest = `${finalDay} ${month} 2021`;
100+
data["Date"]=dateOfContest;
101+
data["Time"] =time;
102+
}
103+
else{
104+
data["Date"] = `${day} ${month} 2021`;
105+
data["Time"] = time;
106+
}
107+
remindDates.push(data);
108+
}
109+
}
110+
fs.writeFileSync("contests.json",JSON.stringify(remindDates));
111+
for(let i in registerUrls){
112+
await tab.goto(registerUrls[i]);
113+
await tab.waitForSelector("input[value='Register']",{visible:true});
114+
await tab.click("input[value='Register']");
115+
await tab.waitForSelector(".welldone");
116+
}
117+
setTimeout(()=>{
118+
119+
},2000);
120+
//goes to whatsapp web to send in notification
121+
await tab.goto("https://web.whatsapp.com/");
122+
await tab.waitForSelector("._13NKt.copyable-text.selectable-text",{visible:true});
123+
await tab.type("._13NKt.copyable-text.selectable-text","Tattu Bear"); // type in contact name to send in the whatsapp msg
124+
await tab.keyboard.press("Enter"); // keypress
125+
await tab.waitForSelector("div[tabindex='-1']",{visible:true,setTimeout:3000});
126+
let readData = fs.readFileSync("contests.json","utf-8");
127+
let lines = readData.split(",");
128+
//reading the data file to type in contest details
129+
for(let j in lines){
130+
let ans = "";
131+
let chars = lines[j];
132+
if(chars!=""){
133+
for(let k in chars){
134+
if(chars[k]!="[" && chars[k]!= "{" && chars[k] && chars[k]!="}" && chars[k]!=']'){
135+
ans+= chars[k];
136+
}
137+
}
138+
}
139+
console.log(ans);
140+
await tab.waitForSelector("._13NKt.copyable-text.selectable-text",{visible:true,setTimeout:2000});
141+
console.log(1);
142+
// let sel2 = await tab.$$("._13NKt.copyable-text.selectable-text");
143+
await tab.type(".p3_M1",ans);
144+
await tab.keyboard.press("Enter");
145+
}
146+
}
147+
148+
main();
Lines changed: 42 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,45 @@
1-
from collections import defaultdict
2-
import math
3-
4-
class Graph:
5-
def __init__(self):
6-
self.nodes = set()
7-
self.archs = defaultdict(list)
8-
self.values = {}
9-
10-
def add_node(self, value):
11-
self.nodes.add(value)
12-
13-
def add_edge(self, init_node, final_node, value):
14-
self.archs[init_node].append(final_node)
15-
self.archs[init_node].append(final_node)
16-
self.values[(init_node, final_node)] = value
17-
18-
19-
def dijkstra(graph, initial):
20-
visited = {initial: 0}
21-
22-
nodes = set(graph.nodes)
23-
24-
while nodes:
25-
min_node = None
26-
for node in nodes:
27-
if node in visited:
28-
if min_node is None:
29-
min_node = node
30-
elif visited[node] < visited[min_node]:
31-
min_node = node
1+
"""Dijkstra's algorithm."""
322

33-
if min_node is None:
34-
break
35-
36-
nodes.remove(min_node)
37-
current_weight = visited[min_node]
38-
39-
for arch in graph.archs[min_node]:
40-
try:
41-
weight = current_weight + graph.values[(min_node, arch)]
42-
except:
43-
weight = current_weight + math.inf
44-
if arch not in visited or weight < visited[arch]:
45-
visited[arch] = weight
46-
47-
return visited
48-
49-
50-
def main():
51-
52-
#initializing values
53-
g = Graph()
54-
g.add_node('a')
55-
g.add_node('b')
56-
g.add_node('c')
57-
g.add_node('d')
58-
59-
g.add_edge('a', 'b', 10)
60-
g.add_edge('b', 'c', 2)
61-
g.add_edge('a', 'c', 1)
62-
g.add_edge('c', 'd', 1)
63-
g.add_edge('b', 'd', 8)
3+
import math
644

65-
#output
66-
print(dijkstra(g, 'a'))
675

68-
main()
6+
class Vertex:
7+
8+
def __init__(self, id):
9+
self.id = str(id)
10+
self.distance = 0
11+
self.neighbors = []
12+
self.edges = {} # {vertex:distance}
13+
14+
def __lt__(self, other):
15+
"""Comparison rule to < operator."""
16+
return self.distance < other.distance
17+
18+
def __repr__(self):
19+
"""Return the vertex id."""
20+
return self.id
21+
22+
def add_neighbor(self, vertex):
23+
"""Add a pointer to a vertex at neighbor's list."""
24+
self.neighbors.append(vertex)
25+
26+
def add_edge(self, vertex, weight):
27+
"""Destination vertex and weight."""
28+
self.edges[vertex.id] = weight
29+
30+
31+
def dijkstra(graph, source, destiny):
32+
"""Dijkstra's Algorithm."""
33+
q = []
34+
for v in graph:
35+
v.distance = math.inf
36+
q.append(v)
37+
source.distance = 0
38+
while q:
39+
v = min(q)
40+
q.remove(v)
41+
for u in v.neighbors:
42+
new = v.distance + v.edges[u.id]
43+
if new < u.distance:
44+
u.distance = new
45+
return destiny.distance

Pattern Searching/src/Rabin Karp.cpp

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

0 commit comments

Comments
 (0)