-
Notifications
You must be signed in to change notification settings - Fork 6
/
flask_orderlunch.py
executable file
·34 lines (30 loc) · 1.07 KB
/
flask_orderlunch.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
#!/usr/bin/python
import datetime
import favorites
import seamless_browser
from flask_frontend import *
thismin = (lambda x: x.hour * 60 + x.minute)(datetime.datetime.now())
wk = None
dry_run=False
for user in User.query.filter_by(minute = thismin):
print "User %s" % user.username
if user.disabled:
print "Disabled."
user.disabled = False
db.session.commit()
continue
try:
def log(msg):
global msgbuf
msgbuf += msg + "\n"
print "Ordering lunch."
selector = favorites.FavoritesSelector(user.favorites.split("\n"), log=log)
login_credentials = "username=%s&password=%s" % (user.username, user.password)
msgbuf = ""
sb = seamless_browser.SeamlessBrowser(log).order(login_credentials, seamless_browser.DEFAULT_PHONE, selector, wk=wk, dry_run=dry_run)
print "Success."
except Exception as e:
msgbuf += "\n%s\n" % repr(e)
report = Message(user_id=user.id, message=msgbuf, created_at=datetime.datetime.now())
db.session.add(report)
db.session.commit()