-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb-maker.py
96 lines (78 loc) · 2.37 KB
/
db-maker.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
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import bs4
import urllib2
import urlparse
import string
import sys
from operator import itemgetter
def getFinalCourseURL(url):
url = url.replace('https','http').strip()
html = urllib2.urlopen(url)
soup = bs4.BeautifulSoup(html)
urls = soup.find_all('a')
return urls[4]['href'].replace('https','http').strip()
def main(curso):
link = "http://fenix.tecnico.ulisboa.pt/cursos/"+curso+"/curriculo"
html = urllib2.urlopen(link)
soup = bs4.BeautifulSoup(html)
urls = soup.find_all('a')
final_html = """\
<tr>
<td>
<h3>Escolher uma cadeira</h3>
</td>
<td>
<select class="form-control" id="courseURL">
"""
silly = 0
lista = []
for url in urls:
if 'disciplina-curricular' in str(url):
silly = 1
url1 = url.get_text().strip()
if not any(url1 in tup for tup in lista):
url2 = getFinalCourseURL(url['href'])
lista.append( (url2, url1) )
else:
if silly == 1:
break
lista = sorted(lista,key=itemgetter(1))
for url2, url1 in lista:
final_html += "\n <option value='%s'>%s</option>" % (url2, url1)
final_html +="""\
</select>
</td>
<td>
<button type="button" class="btn btn-primary" onclick="processCourseURL()"><span class="glyphicon glyphicon-plus"></span></button>
</td>
</tr>
"""
return final_html.encode('utf-8','ignore')
cursos = ['meaer', 'meambi', 'lean', 'mebiol', 'mebiom', 'mec', 'lee', 'meec', 'meft', 'legm', 'legi', 'leic-a', 'leic-t', 'lemat', 'memec', 'meq', 'lerc', 'lmac']
html = ""
for curso in cursos:
html += """\
<?php case '{0}': ?>
<div id="loading">
<h1>A calcular os melhores horários...</h1>
</div>
<div id='errorMessage' style="font-family:'Verdana';color:#DD0000;visibility:hidden">Ocorreu um erro na obtenção da disciplina. É possível que o URL esteja mal formado.</div>
<div class='container'>
<form action="generate_timetables.php" method="post">
<table style="width:70%;">
""".format(curso)
html += main(curso)
html += """\
<tr><td></td><td>
<div id="courses">
</div>
</td><td></td></tr>
<tr><td></td><td><input class="btn btn-primary-outline" type="submit" value="Submit"></td><td></td></tr>
</table>
</form>
</div>
</div>
<?php break ?>
"""
print(html)