-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.py
71 lines (56 loc) · 1.96 KB
/
backend.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
from code_ptit import CodePTIT
from git_content import GitContent
from chrome_module import *
import random
from time import sleep
import traceback
class Backend:
def __init__(self):
self.code_ptit = CodePTIT()
self.git_content = GitContent()
self.driver = None
def login(self):
self.driver = getDriver()
self.driver.get('https://code.ptit.edu.vn')
def login_finished(self):
try:
if self.driver:
self.driver.quit()
except:
pass
def run(self, type, limit = 30, min_wait = 30, max_wait = 100):
type = type.lower()
if not self.driver:
driver = getDriver()
else:
driver = self.driver
self.code_ptit.select_language(driver, type)
sleep(5)
tasks = self.code_ptit.get_unsolved_tasks(self.code_ptit.get_num_of_page(driver), driver)
for task in tasks:
if limit <= 0:
break
try:
if task.get('url', None):
file_path = self.git_content.get_file(type, task.get('id'), task.get('title'))
if file_path == 'file not founded':
continue
self.code_ptit.upload_file(driver, task.get('url'), file_path)
sleep(random.uniform(min_wait, max_wait))
limit -= 1
else:
continue
except:
traceback.print_exc()
try:
if driver:
driver.quit()
except:
traceback.print_exc()
if __name__ == '__main__':
be = Backend()
# login to code ptit
driver = getDriver()
driver.get('https://code.ptit.edu.vn')
input('continue once finished logging in')
be.run(driver, 'java', limit= 10, min_wait= 10, max_wait=30)