-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmanage.py
More file actions
87 lines (62 loc) · 1.94 KB
/
manage.py
File metadata and controls
87 lines (62 loc) · 1.94 KB
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
import os
from datetime import datetime
from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand
from web import app, db
from dbupdate import (update_ratebeer as rb_update, update_pol_beers,
update_pol_shops, update_pol_stock, update_adminareas,
update_brewery_positions)
manager = Manager(app)
DIR = os.path.dirname(os.path.realpath(__file__))
migrate = Migrate()
migrate.init_app(app, db, directory=DIR + '/alembic')
manager.add_command('db', MigrateCommand)
def log_write(message):
with open('log.txt', 'a') as logfile:
logfile.write('%s %s\n' % (message, datetime.now()))
@manager.command
def update_ratebeer():
print 'Importing data from ratebeer'
rb_update(app.config.get('SQLALCHEMY_DATABASE_URI', None))
@manager.command
def update_positions():
print 'update brewery positions'
conn_str = app.config.get('SQLALCHEMY_DATABASE_URI', None)
update_brewery_positions(conn_str)
@manager.command
def update_pol():
print 'Importing data vinmonopolet'
conn_str = app.config.get('SQLALCHEMY_DATABASE_URI', None)
print 'Import shops'
update_pol_shops(conn_str)
print 'Import beers'
update_pol_beers(conn_str)
print 'Import stock'
update_pol_stock(conn_str)
@manager.command
def update_osm_cron():
try:
update_positions()
log_write('Updated OSM')
except Exception:
log_write('OSM failed')
@manager.command
def update_ratebeer_cron():
try:
update_ratebeer()
log_write('Updated RB')
except Exception:
log_write('RB failed')
@manager.command
def update_pol_cron():
try:
update_pol()
log_write('Updated POL')
except Exception:
log_write('POL failed')
@manager.command
def update_admin():
conn_str = app.config.get('SQLALCHEMY_DATABASE_URI', None)
update_adminareas(conn_str)
if __name__ == '__main__':
manager.run()