-
Notifications
You must be signed in to change notification settings - Fork 2
/
SemPapers.py
210 lines (191 loc) · 6.15 KB
/
SemPapers.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import prettytable
import webbrowser
import requests
import itertools
import threading
import time
import sys
import datetime
from bs4 import BeautifulSoup
from prettytable import PrettyTable
from time import sleep
from sys import exit
from os import system, name
stack_url=[]
def clear():
# for windows
if name == 'nt':
_ = system('cls')
# for mac and linux(here, os.name is 'posix')
else:
_ = system('clear')
def year(url):
clear()
year_url=url
try:
page = requests.get(url)
soup = BeautifulSoup(page.content,'html.parser')
div=soup.findAll('div', xmlns="http://di.tamu.edu/DRI/1.0/")
ul=div[0].findAll('ul')
li=ul[0].findAll('li')
hyper=li[0].a['href']
url='http://dspace.amritanet.edu:8080/'
url+=hyper
page = requests.get(url)
soup = BeautifulSoup(page.content,'html.parser')
t=PrettyTable(['No','Subjects'])
div=soup.findAll('div', class_="file-list")
subdiv=div[0].findAll('div',class_="file-wrapper clearfix")
for i in range(len(subdiv)):
title=subdiv[i].findAll('div')
span=title[1].div.findAll('span')
t.add_row([i+1,span[1]['title']])
t.add_row([len(subdiv)+1,"Back"])
t.align='l'
print(t)
while(True):
ch=int(input("Enter your choice: "))
if(ch>0 and ch<=len(subdiv)):
title=subdiv[ch-1].findAll('div')
link=title[0].a['href']
url='http://dspace.amritanet.edu:8080/'
url+=link
break
elif(ch == len(subdiv)+1):
semchoose(stack_url.pop())
else:
print("Please enter a valid input!")
except:
print("UNEXPECTED ERROR! :(")
exit()
print("Please wait till the browser opens ! ")
webbrowser.open(url, new=0, autoraise=True)
ch=int(input('Do you want to continue ? \nPress 1 for Yes and 0 for No : '))
if(ch==0):
exit()
else:
year(year_url)
def semchoose(url):
clear()
try:
params_url =url
page = requests.get(url)
soup = BeautifulSoup(page.content,'html.parser')
t=PrettyTable(['No','Available Assessments'])
div=soup.findAll('div', id="aspect_artifactbrowser_CommunityViewer_div_community-view")
ul=div[0].findAll('ul')
if(len(ul)>1):
li=ul[1].findAll('li')
else:
li=ul[0].findAll('li')
for i in range(len(li)):
t.add_row([i+1,li[i].a.text.strip()])
t.add_row([len(li)+1, "Back"])
t.align = "l"
print(t)
while(True):
ch=int(input("Enter your choice: "))
if(ch>0 and ch<=len(li)):
url='http://dspace.amritanet.edu:8080/'
url+=li[ch-1].a['href']
break
elif(ch == len(li)+1):
sem_table(stack_url.pop())
else:
print("Please enter a valid input !")
except:
print("\nUNEXPECTED ERROR ! :( ")
sleep(3)
exit()
stack_url.append(params_url)
year(url)
def sem_table(url):
clear()
try:
stack_url.append(url)
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
t = PrettyTable(['No', 'Semesters'])
div = soup.findAll('div', id="aspect_artifactbrowser_CommunityViewer_div_community-view")
li = div[0].ul.findAll('li')
for i in range(len(li)):
t.add_row([i + 1, li[i].a.text.strip()])
t.add_row([(len(li) + 1), "Back"])
t.align = "l"
print(t)
while (True):
ch = int(input("Enter your semester : "))
if (ch > 0 and ch <= len(li)):
url = 'http://dspace.amritanet.edu:8080/'
url += li[ch - 1].a['href']
break
elif (ch == len(li) + 1):
start()
else:
print("Please enter a valid input !")
except Exception as e:
print("\nUNEXPECTED ERROR ! :( ")
sleep(3)
exit()
semchoose(url)
def start():
clear()
url="http://dspace.amritanet.edu:8080/xmlui/handle/123456789/"
try:
page = requests.get(url)
print("\n")
t=PrettyTable(['No','Courses'])
t.add_row(["1","B.Tech"])
t.add_row(["2","BA Communication"])
t.add_row(["3","MA Communication"])
t.add_row(["4","Integrated MSc & MA"])
t.add_row(["5","MCA"])
t.add_row(["6","MSW"])
t.add_row(["7","M.Tech"])
t.add_row(["8","Exit"])
t.align="l"
print(t)
while(True):
print("\n")
ch=int(input("Enter your choice : "))
if(ch<9 and ch>0):
if(ch==1) :
url+="150"
elif(ch==2) :
url+="893"
elif(ch==3) :
url+="894"
elif(ch==4) :
url+="903"
elif(ch==5) :
url+="331"
elif(ch==6) :
url+="393"
elif(ch==7) :
url+="279"
elif (ch==8):
exit()
break
else:
print("Please enter a valid input ! ")
except Exception as e:
print("\nOOPS! There was an unexpected error.\nExiting in few seconds... ")
sleep(4)
exit()
sem_table(url)
url="http://dspace.amritanet.edu:8080"
print("\nHELLO! Ever wanted to use Amrita Repository on PC ? \nWell, here's my Python Script that does the same job as the app. \nHave a look at your question papers without wasting time !! \n")
print("Please ensure you're connected to Amrita Wi-Fi for a smooth experience :)\n")
print("Report bugs to : [email protected]")
now = datetime.datetime.now()
print("(c) "+str(now.year)+" Rajkumar\n")
done=10
for c in itertools.cycle(['|', '/', '-', '\\']):
if not(done):
break
sys.stdout.write('\rPlease wait..' + c)
sys.stdout.flush()
done=done-1
time.sleep(0.1)
sys.stdout.flush()
start()