-
Notifications
You must be signed in to change notification settings - Fork 0
/
python.py
172 lines (152 loc) · 5.64 KB
/
python.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
from selenium import webdriver
from bs4 import BeautifulSoup
from time import sleep
#import mysql.connector
#mydb = mysql.connector.connect(
# host="HOST",
# database="DATABASE",
# user="USER",
# password="PASSWORD"
#)
#mycursor = mydb.cursor()
driver = webdriver.Chrome(executable_path=r"C:\chromedriver\chromedriver.exe")
driver.get("https://care.srmist.edu.in/srmstudentskill/login")
n = input("Enter Confirmation ")
maindata = []
maintestcase_data = []
skippeddata = []
codedata = []
number = 1
url_no = 1812110#1811110
old_url = 1812110#1811110
for i in range(11,21):
title = []
answer = []
IO = []
mainlist = []
codelist = []
codestr = ""
print("-----------------------------------------------------")
print("Loading Question ",i)
print("-----------------------------------------------------")
url = "https://care.srmist.edu.in/srmstudentskill/student/solve/"
no = url_no + number
number = number + 1
if i == 100:
url_no = old_url + 100;
number = 1
elif i == 200:
url_no = old_url + 200;
number = 1
elif i == 300:
url_no = old_url + 300;
number = 1
elif i % 10 == 0:
url_no = url_no + 1000
number = 1
url = url + str(no)
driver.execute_script("window.open('https://www.google.com');")
driver.switch_to.window(driver.window_handles[-1])
driver.get(url)
sleep(2)
content = driver.page_source
soup = BeautifulSoup(content, features="html5lib")
# print(soup.findAll('div', attrs={'class':'list-item'}))
# print(len(soup.findAll('div', attrs={'class':'list-item'})))
if soup.findAll('div', attrs={'class': 'list-item'}):
for a in soup.findAll('div', attrs={'class': 'list-item'}):
title_sub = a.find('a', attrs={'class': 'title'})
# print(title_sub.text)
ans_sub = a.findAll('a', attrs={'_ngcontent-c16': ''})
# print(ans_sub[1].text)
title.append(title_sub.get_text(separator="(br)").strip())
answer.append(ans_sub[1].get_text(separator="(br)").strip())
print(title)
print(answer)
for b in soup.findAll('div', attrs={'class': 'list-item ng-star-inserted'}):
name = b.findAll('code', attrs={'_ngcontent-c16': ''})
for n in name:
IO.append(n.get_text(separator="(br)").strip())
print(IO)
count = 3
for j in range(0, len(IO), 2):
maintestcase = []
maintestcase.append(i)
maintestcase.append(title[count])
maintestcase.append(IO[j])
maintestcase.append(IO[j + 1])
count = count + 1
maintestcase = list(maintestcase)
maintestcase_data.append(maintestcase)
print(maintestcase)
mainlist.append(i)
mainlist.append(answer[0])
mainlist.append(title[1])
mainlist.append(answer[1])
mainlist.append(answer[2])
#mainlist = list(mainlist)
#maindata.append(mainlist)
for c in soup.findAll('pre', attrs={'role': 'presentation'}):
code_sub = c.findAll('span', attrs={'role': 'presentation'})
for codei in code_sub:
codelist.append(codei.get_text().strip())
#print(codelist)
for l in codelist:
codestr = codestr + l
codestr = codestr + "(br)"
#print(codestr)
icon = driver.find_element_by_css_selector('div.CodeMirror-vscrollbar')
size = icon.size
# print(size['height'])
mainlist.append(codestr)
mainlist.append(size['height'])
#print(mainlist)
mainlist = list(mainlist)
maindata.append(mainlist)
#print("START CODE")
code_string = []
for m in maindata:
print(m[0])
print("Size is " + str(m[6]))
cd = list(m[5].split('(br)'))
code_string.append(m[5])
if int(m[6]) > 0:
code_string = []
codestring = ""
print("Data is Large...")
print("Enter The Code Manually and Close with a <br> tag at the end")
while True:
line = input()
if line == "<br>":
break
code_string.append(line)
multiline_string = "\n".join(code_string)
for ml in code_string:
codestring = codestring + ml
codestring = codestring + "(br)"
#print(codestring)
#print(len(maindata[0][5]))
maindata[i][5] = codestring
#print("----------------------------------")
maindata[i].pop(6)
#print(maindata)
# print(content)
#print("---------------------------------")
else:
print("Skipped", i)
skippeddata.append(i)
print(maindata)
print(maintestcase_data)
print()
print("-----------------------------------------------------------------")
print(str(len(maindata))+" Questions Loaded Successfully")
print(str(len(skippeddata))+" Questions Skipped...")
if len(skippeddata) > 0:
print("List of skipped data is ")
print(skippeddata)
print("-----------------------------------------------------------------")
#sqlformula1 = "INSERT INTO elabdata (id, SESSION, QUESTION_NO, QUESTION_NAME, QUESTION_DESC, CODE) VALUES (%s, %s, %s, %s, %s, %s)"
#mycursor.executemany(sqlformula1, maindata)
#sqlformula2 = "INSERT INTO elabtestcase (dataid, TESTCASE_NO, INPUT, OUTPUT) VALUES (%s, %s, %s, %s)"
#mycursor.executemany(sqlformula2, maintestcase_data)
#mydb.commit()