-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
129 lines (106 loc) · 3.82 KB
/
app.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import os, sys
#sys.path.append('C:\Python27\Lib\site-packages\\flask-0.9-py2.7.egg')
#sys.path.append('C:\Python27\Lib\site-packages\\requests-0.13.1-py2.7.egg')
#print sys.version
import gflags
import httplib2
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
import requests
from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash, jsonify
from research import crawler, google_API
# CONFIGURATIONS
DEBUG = True
app = Flask(__name__)
app.config.from_object(__name__)
FLOW = OAuth2WebServerFlow(
client_id='543969079784-lngogo23fltd477geejt005q8h35plb0.apps.googleusercontent.com',
client_secret='gqDbB6ciBkgc6Vci_qvJaUPR',
scope='https://www.googleapis.com/auth/calendar',
redirect_uri='http://morning-mesa-6317.herokuapp.com/auth',
user_agent='SSC-0.2')
@app.route("/")
def landing():
return render_template('landing.html')
@app.route("/home")
def home():
return render_template('home.html')
@app.route("/research")
def research():
return render_template('research.html')
@app.route("/search")
def search():
search_query = request.args['search_query']
search_target = request.args['search_target']
if search_target == 'ticketmaster':
return render_template('iframe_search.html', search_query=search_query, ticketmaster=True)
else:
return render_template('iframe_search.html', search_query=search_query, stubhub=True)
@app.route("/research/send_email")
def send_email():
crawler.collect_upcomming_sales('./Upcoming_sales.txt')
crawler.send_data_by_email('./Upcoming_sales.txt')
response = { 'status' : '200'}
return jsonify(response)
@app.route("/calendar", methods=['GET', 'POST'])
def calendar():
if request.method == 'GET':
return render_template('calendar.html')
elif request.method == 'POST':
if is_google_auth():
http = get_credentials()
service = build(serviceName='calendar', version='v3', http=http,
developerKey='AIzaSyD4CyU_Y0ydHzD5zjMGmV7QjpwwHj62XUY')
date = request.form['date']
artist = request.form['artist']
location = request.form['location']
sale_type = request.form['sale_type']
#print date + '-' + artist + '-' + location + '-' + sale_type
google_API.create_calendar_event(service, date, artist, location, sale_type)
return 'Done'
else:
return authenticate()
else:
return "Method not supported"
@app.route("/tickets/data")
def data():
return render_template('data.html')
@app.route("/tickets/buy")
def buy():
return render_template('buy.html')
### METHODS FOR API AUTHENTICATIONS
@app.route("/auth")
def calendar_auth():
authenticate(request.args)
return 'BOOOM CHAKALAKA'
#### UTILITY METHODS ####
def is_google_auth():
storage = Storage('googleAPI.dat')
credentials = storage.get()
if credentials is None or credentials.invalid == True:
return None
else:
return True
def get_credentials():
storage = Storage('googleAPI.dat')
credentials = storage.get()
http = httplib2.Http()
http = credentials.authorize(http)
return http
def authenticate(code=None):
if code:
credentials = FLOW.step2_exchange(code)
store_credentials(credentials)
else:
auth_uri = FLOW.step1_get_authorize_url()
return auth_uri
def store_credentials(credentials):
storage = Storage('googleAPI.dat')
storage.put(credentials)
#####################################################################################################################
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)
#app.run()