-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhackathon.py
188 lines (142 loc) · 6.52 KB
/
hackathon.py
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from PIL import Image
from getpass import getpass
from tabulate import tabulate
from terminaltables import AsciiTable
import time
import os
import linecache
options= webdriver.ChromeOptions()
options.headless=True
PATH = r"C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH,options=options)
#write code to login!!!!
# driver.get('https://codeforces.com/enter?back=%2F')
# username=driver.find_element_by_id('handleOrEmail')
# print('Enter Username: ')
# #User Enters his/her username here:
# username.send_keys(input())
# password=driver.find_element_by_id('password')
# #User enters his/her password here:
# pwd=getpass("Please enter password (Your password will not appear on screen while typing):")
# password.send_keys(pwd)
# button=driver.find_element_by_class_name('submit')
# button.click()
# time.sleep(2)
# print("Please enter your command, type help for list of commands: ")
# command=input()
while True:
try:
print("Please enter your command, type help for list of commands: ")
command=input()
if command=='upcoming' or command=='Upcoming':
driver.get("https://codeforces.com/contests?complete=true")
time.sleep(1)
name_list=[]
date_list=[]
index=2
while True:
try:
status=driver.find_element_by_xpath(('//*[@id="pageContent"]/div[1]/div[1]/div[6]/table/tbody/tr[{}]/td[5]').format(index))
status_text=status.text
if "Before" in status_text:
contest=driver.find_element_by_xpath(('//*[@id="pageContent"]/div[1]/div[1]/div[6]/table/tbody/tr[{}]/td[1]').format(index))
contest_name=contest.text
date=driver.find_element_by_xpath(('//*[@id="pageContent"]/div[1]/div[1]/div[6]/table/tbody/tr[{}]/td[3]').format(index))
date_text=date.text
name_list.append(contest_name)
date_list.append(date_text)
index+=1
except:
break
titles = ['Name','Date']
data = [titles] + list(zip(name_list, date_list))
for i, d in enumerate(data):
line = '|'.join(str(x).ljust(89) for x in d)
print(line)
if i == 0:
print('-' * len(line))
continue
if command=='help' or command=='Help':
print("----------------------------------------------------------------------")
print("help | gives the list of commands")
print("----------------------------------------------------------------------")
print("upcoming | gives the list of upcoming CodeForces Contests")
print("----------------------------------------------------------------------")
print("rating | gives your current rating")
print("----------------------------------------------------------------------")
print("exit | quits the program")
print("----------------------------------------------------------------------")
continue
if command=='rating' or command=='Rating':
print("Enter codeforces handle of user(It is case-sensitive): ")
userhandle=input()
driver.get('https://codeforces.com/api/user.rating?handle={}'.format(userhandle))
content=driver.find_element_by_tag_name('pre').text
if content.rfind("newRating")!=-1:
bracket_index=content.rfind("}",0,-2)
print(content[content.rfind("newRating")+11:bracket_index])
elif "FAILED" in content:
print("USER NOT FOUND !! INVALID HANDLE")
else:
print("Unrated")
continue
elif command=='exit':
break
except :
print("Invalid command , type exit to quit")
continue
'''
if command=='upcoming' or command=='Upcoming':
driver.get("https://codeforces.com/contests?complete=true")
time.sleep(1)
name_list=[]
date_list=[]
index=2
while True:
try:
status=driver.find_element_by_xpath(('//*[@id="pageContent"]/div[1]/div[1]/div[6]/table/tbody/tr[{}]/td[5]').format(index))
status_text=status.text
if "Before" in status_text:
contest=driver.find_element_by_xpath(('//*[@id="pageContent"]/div[1]/div[1]/div[6]/table/tbody/tr[{}]/td[1]').format(index))
contest_name=contest.text
date=driver.find_element_by_xpath(('//*[@id="pageContent"]/div[1]/div[1]/div[6]/table/tbody/tr[{}]/td[3]').format(index))
date_text=date.text
name_list.append(contest_name)
date_list.append(date_text)
index+=1
except:
break
titles = ['Name','Date']
data = [titles] + list(zip(name_list, date_list))
for i, d in enumerate(data):
line = '|'.join(str(x).ljust(89) for x in d)
print(line)
if i == 0:
print('-' * len(line))
if command=='help' or command=='Help':
print("----------------------------------------------------------------------")
print("help | gives the list of commands")
print("----------------------------------------------------------------------")
print("upcoming | gives the list of upcoming CodeForces Contests")
print("----------------------------------------------------------------------")
print("rating | gives your current rating")
print("----------------------------------------------------------------------")
if command=='rating' or command=='Rating':
print("Enter codeforces handle of user(It is case-sensitive): ")
userhandle=input()
driver.get('https://codeforces.com/api/user.rating?handle={}'.format(userhandle))
content=driver.find_element_by_tag_name('pre').text
if content.rfind("newRating")!=-1:
bracket_index=content.rfind("}",0,-2)
print(content[content.rfind("newRating")+11:bracket_index])
elif "FAILED" in content:
print("USER NOT FOUND !! INVALID HANDLE")
else:
print("Unrated")
'''