-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
80 lines (57 loc) · 1.85 KB
/
manage.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
#!/usr/bin/env python
"""
Manage.py
=========
Manager script for teh data_vis project.
Can start up a server instance, run analyses and purge database records.
"""
from pathlib import Path
from flask.ext.script import Manager
from data_vis import app
from data_vis.models import get_session, Faculty
manager = Manager(app)
@manager.command
def reset_db():
""" Initialise the database tables.
"""
db_file = Path('courses.db')
# Delete database file
if db_file.exists():
print('SQLite file exists, removing it.')
db_file.unlink()
else:
print('No SQLite file found.')
from data_vis.models import Base, engine
Base.metadata.create_all(engine)
session = get_session()
# Load Faculties.
faculty_info = [
('BEL', 'Business, Economics and Law', 'index.html?id=4405'),
('EAIT', 'Engineering, Architecture and Information Technology', 'index.html?id=4406'),
('HABS', 'Health and Behavioural Sciences', 'http://health.uq.edu.au/health-behavioural-sciences'),
('HASS', 'Humanities and Social Sciences', 'http://hass.uq.edu.au/'),
('MBS', 'Medicine and Biomedical Sciences', 'http://health.uq.edu.au/medicine-biomedical-sciences'),
('SCI', 'Science', 'index.html?id=4404'),
]
# Add faculties to the database.
for fac_id, title, href in faculty_info:
fac_obj = Faculty(id=fac_id, title=title, html_reference=href)
session.merge(fac_obj)
session.commit()
@manager.command
def run_debug():
"""
Run a debug server.
"""
app.run(debug=True)
@manager.command
def seed_programs():
from data_vis.scraper import scrape_programs
reset_db()
scrape_programs()
@manager.command
def seed_majors():
from data_vis.scraper import scrape_majors
scrape_majors()
if __name__ == "__main__":
manager.run()