-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
113 lines (82 loc) · 2.83 KB
/
main.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 12 20:12:44 2017
@author: Sarai
"""
import os
from flask import Flask, request, render_template, redirect, session
import tweepy
import crud, sign_in
#import Sturmtest as st
app = Flask(__name__)
app.secret_key = os.environ['session_secret_key']
consumer_key = os.environ['consumer_key']
consumer_secret = os.environ['consumer_secret']
@app.route("/")
def start():
# TODO: Write a start page describing purpose and basic philosophy.
return redirect("/receipts", code=302)
@app.route('/login')
def send_token():
return sign_in.send_token()
@app.route("/verify")
def get_verification():
return sign_in.get_verification()
@app.route("/approve")
def approvals(approval_msg=""):
return crud.get_approvals(approval_msg)
@app.route('/approve', methods=['POST'])
def approve_receipts():
# Get values from post request, and update indicated approvals in db.
try:
approved_ids = request.form.getlist('approvals')
for n in approved_ids:
if n.isdigit():
n = int(n)
else:
raise ValueError("Item in array is not an integer: " + str(n))
return crud.post_approvals(approved_ids)
except BaseException as e:
print("Error in approve_receipts():", e)
return render_template('error.html', error_msg = e)
@app.route("/receipts")
def receipts():
args = request.args
return crud.get_receipts(args)
@app.route("/receipts_json")
def receipts_json():
args = request.args
return crud.get_receipts_json(args)
@app.route("/search/<string:user_searched>/")
def search_user_url(user_searched):
args = request.args
print("Searching for user @" + user_searched)
return search_user(user_searched, args)
@app.route('/search', methods=['POST'])
def search_user_form():
user_searched = request.form['search_user']
args = request.args
print("Searching for user @" + user_searched)
return search_user(user_searched, args)
def search_user(user_searched, args):
return crud.search_receipts_for_user(user_searched, args)
@app.route('/sturm')
def sturm():
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(session['key'], session['secret'])
return render_template('app.html',
logged_in = session.get('logged_in', False),
show_approvals = session.get('show_approvals', False))
@app.route('/logout')
def logout():
# remove variables from session
if 'request_token' in session:
del session['request_token']
if 'logged_in' in session:
del session['logged_in']
if 'show_approvals' in session:
del session['show_approvals']
return redirect('../')
if __name__ == '__main__':
app.debug = True
app.run()