-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathacadHist.py
66 lines (59 loc) · 2.63 KB
/
acadHist.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
from bs4 import BeautifulSoup
import mechanize
import cookielib
import re
def getUserData(username,password):
br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.set_debug_redirects(True)
br.set_handle_robots(False)
br.set_handle_refresh(False)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
br.open("https://wesep.wesleyan.edu/cgi-perl/session.cgi")
br.select_form(nr=0)
br["username"] = username
br["password"] = password
br.submit()
request = mechanize.Request("https://wesep.wesleyan.edu/cgi-perl/students/academic_history/academic_history.cgi")
request.add_header('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')
request.add_header("Referer", "https://wesep.wesleyan.edu/cgi-perl/portfolio_maker/get_info.cgi/?info=left&portfolio_type=Student&portfolio="+username+"&indicatorID=&expire=05/23/2013%2009:23%20AM")
cj.add_cookie_header(request)
raw = br.open(request)
soup = BeautifulSoup(raw)
html = soup.prettify()
head = soup.find_all('center')[1].get_text().strip().split('\n')
x = {'name':str(head[0][5:-4].strip()), 'year':int(head[0][-4:].strip()),
'major':str(head[1].split(':')[1].strip()), 'minor':str(head[2].split(':')[1].strip()), 'certificate':str(head[3].split(':')[1].strip())}
preCred = 0.0
preReq = False
#classes dumped in one array
x['classes'] = []
for tr in soup.find_all('tr'):
if "Cumulative Earned Credits" not in tr.get_text():
if tr.find_all('a') != [] and 'ALTGPA' not in tr.get_text():
name = str(tr.find_all('a')[0].get_text().split("-")[0])
credit = str(tr.find_all('td', align="right")[0].get_text().strip())
current = False
if credit[0] == '(' and credit[-1] == ')':
credit = credit.strip('(').strip(')')
current = True
credit = float(credit)
x['classes'].append({"name": name, "credit": credit, "current": current})
if tr.find_all(text=re.compile("Pre-Matric")) != []:
preReq = True
elif preReq == True:
preCred = float(str(tr.find_all('td', align="right")[0].get_text().strip()))
preReq = False
x['preMatric'] = preCred
#classes sorted by semester
# for tr in soup.find_all('tr'):
# if "Cumulative Earned Credits" not in tr.get_text():
# if "Fall" in tr.get_text() or "Spring" in tr.get_text() or "Summer" in tr.get_text():
# o = str(tr.find_all('b')[0].get_text())
# x[o]= []
# current = o
# if tr.find_all('a') != [] and 'ALTGPA' not in tr.get_text():
# o = str(tr.find_all('a')[0].get_text().split("-")[0])
# x[current].append(o)
return x