-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmint_server.py
40 lines (31 loc) · 1.09 KB
/
mint_server.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
from flask import Flask
from flask import request
import time
import datetime
import mintapi
import simplejson
import urllib
app = Flask(__name__)
@app.route("/")
def home():
return "Let's get minty, yeah!"
@app.route("/get_mint")
def get_mint_account():
u = urllib.unquote(request.args.get('u'))
p = urllib.unquote(request.args.get('p'))
mint = mintapi.Mint(u, p)
all_accounts = mint.get_accounts()
# Need to sanitize python dates to be able to
# convert to JSON
for account in all_accounts:
if 'closeDateInDate' in account:
account['closeDateInDate'] = int(time.mktime(account['closeDateInDate'].timetuple()))
if 'lastUpdatedInDate' in account:
account['lastUpdatedInDate'] = int(time.mktime(account['lastUpdatedInDate'].timetuple()))
if 'addAccountDateInDate' in account:
account['addAccountDateInDate'] = int(time.mktime(account['addAccountDateInDate'].timetuple()))
if 'fiLastUpdatedInDate' in account:
account['fiLastUpdatedInDate'] = int(time.mktime(account['fiLastUpdatedInDate'].timetuple()))
return simplejson.dumps(all_accounts)
if __name__ == "__main__":
app.run()