-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
executable file
·86 lines (64 loc) · 2.35 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
81
82
83
84
85
86
#!/usr/bin/env python
from __future__ import absolute_import, print_function
import os
import sys
import datetime
import baker
import bcrypt
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
import splitbee
from splitbee.models import *
from splitbee.util import gen_random
from splitbee import config
bind_db(config.get_db())
@baker.command
def syncdb():
print("Synchronizing database...", end='')
drop_tables()
create_tables()
print(" done!")
@baker.command
def run(port=8000):
from splitbee.app import app
from wsgiref import simple_server
host = '127.0.0.1'
print("Serving HTTP on %s port %d ..." % (host, port))
httpd = simple_server.make_server(host, port, app)
try:
httpd.serve_forever()
except KeyboardInterrupt:
print('')
@baker.command
def add_test_data():
# Add test users
print("Adding users..."); sys.stdout.flush()
u1 = User.create(email='[email protected]',
password=bcrypt.hashpw("hello", bcrypt.gensalt()))
u2 = User.create(email='[email protected]',
password=bcrypt.hashpw("goodbye", bcrypt.gensalt()))
# Add test bills
print("Adding bills..."); sys.stdout.flush()
b1 = Bill.create(id='WSxav972', description="breakfast at Foo")
b2 = Bill.create(id='Dp84UxFi', description="lunch at Bar")
b3 = Bill.create(id='nsUyGz42', description="dinner at Baz")
# Add components of a bill
print("Adding bill components..."); sys.stdout.flush()
c1 = BillComponent.create(bill=b1, user=u1, amount=10.0)
c2 = BillComponent.create(bill=b1, user=u2, amount=15.0)
c3 = BillComponent.create(bill=b2, user=u1, amount= 1.0)
c4 = BillComponent.create(bill=b2, user=u2, amount=11.0)
c5 = BillComponent.create(bill=b3, user=u1, amount=25.0)
c6 = BillComponent.create(bill=b3, user=u2, amount=18.0)
@baker.command
def get_tokens(email):
user = User.get(User.email == email)
print("Tokens for user '%s' (ID = %d):" % (email, user.id))
for token in Token.select().where(Token.user == user).\
order_by(Token.timestamp.desc()):
print('\t%s - created at %s (%d seconds ago)' % (
token.id,
token.timestamp.strftime("%Y-%m-%d %H:%M:%S UTC"),
(datetime.utcnow() - token.timestamp).total_seconds(),
))
if __name__ == "__main__":
baker.run()