-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrun.py
47 lines (35 loc) · 1.16 KB
/
run.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
import os
import argparse
from werkzeug.security import generate_password_hash
from app import app, db
from app.models import User, Pair, Company, TypeformAPI
def database_setup():
"""
Setup database
"""
# Create tables
db.drop_all()
db.create_all()
# Add admin account
admin = User(login=app.config['ADMIN_USER'],\
password=generate_password_hash(app.config['ADMIN_PASS']))
db.session.add(admin)
# Initialize 'since' variable
newest_date_submit = Pair(key="since", val=0)
db.session.add(newest_date_submit)
# Commit changes to the database
db.session.commit()
print 'Database setup completed. Now run the app without --setup.'
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Run Founded in Romania app')
parser.add_argument('--setup', dest='run_setup', action='store_true')
args = parser.parse_args()
if args.run_setup:
database_setup()
else:
try:
import logging
logging.basicConfig(filename='error.log', level=logging.DEBUG)
app.run()
except Exception:
app.logger.exception('Failed')