forked from ab-anand/Automation-Bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codechef_submission.py
51 lines (35 loc) · 1.19 KB
/
codechef_submission.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
from selenium import webdriver
import getpass
import time
# codechef credentials for login
username = "nikhilksingh97"
password = getpass.getpass("Password: ")
# problem code
problem = input("Problem code: ")
# submission code
submission_file = input("Submission file: ")
with open(submission_file, 'r') as f:
code = f.read()
# start a browser session
browser = webdriver.Firefox()
# open link in browser
browser.get('https://www.codechef.com')
# login
nameElem = browser.find_element_by_id('edit-name')
nameElem.send_keys(username)
passElem = browser.find_element_by_id('edit-pass')
passElem.send_keys(password)
browser.find_element_by_id('edit-submit').click()
# open submission page
browser.get("https://www.codechef.com/submit/" + problem)
# sleep function to let web components load in case of slow internet connnection
time.sleep(10)
# click on toggle button to open simple text mode
browser.find_element_by_id("edit_area_toggle_checkbox_edit-program").click()
# submit the code
inputElem = browser.find_element_by_id('edit-program')
inputElem.send_keys(code)
browser.find_element_by_id("edit-submit").click()
# get result
result = browser.find_element_by_id("display_result").text
print(result)