-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from stevenpollack/heroku_app
created first version of heroku app... Still doesn't have caching.
- Loading branch information
Showing
17 changed files
with
265 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: gunicorn app:app --log-file - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
from flask import Flask, request, json, Response, redirect | ||
from requests import HTTPError | ||
from warnings import warn | ||
from iron_cache import IronCache | ||
from dairy_queen.theatre import Theatre | ||
import requests | ||
from json import loads, dumps | ||
|
||
#double_dip_cache = IronCache(name='double_dips') | ||
|
||
app = Flask(__name__) | ||
@app.route('/') | ||
def route_to_apiary(): | ||
apiary_io = 'http://docs.dairyqueen1.apiary.io/' | ||
return (redirect(apiary_io, code=302)) | ||
|
||
def hello_world(): | ||
try: | ||
cache_key = create_cache_key(near, days_from_now) | ||
double_dips = json.loads(double_dip_cache.get(key=cache_key).value) | ||
warn('Fetched results from cache with key: ' + cache_key) | ||
except ValueError as ve: | ||
warn(str(ve)) | ||
showtimes = json.dumps({'error': '`date` must be a base-10 integer'}) | ||
status = 400 | ||
except HTTPError as e: | ||
warn(str(e)) | ||
return('hello world') | ||
|
||
@app.route('/double-dips', methods=['GET']) | ||
def get_doubledips(): | ||
location = request.args.get('location') | ||
days_from_now = request.args.get('days_from_now') | ||
max_waiting_time = request.args.get('max_wait_mins') | ||
max_overlap_time = request.args.get('max_overlap_mins') | ||
|
||
status = None | ||
msg = None | ||
mimetype = 'application/json' | ||
|
||
if location is None or not isinstance(location, str): | ||
status = 400 | ||
msg = "'location' is mandatory and must be a string." | ||
|
||
if days_from_now is not None: | ||
try: | ||
days_from_now = int(days_from_now) | ||
except Exception: | ||
status = 400 | ||
msg = "'days_from_now' must be a base-10 integer." | ||
resp = Response(dumps({'msg': msg}), status=status, mimetype=mimetype) | ||
return resp | ||
else: | ||
days_from_now = 0 | ||
|
||
if max_waiting_time is not None: | ||
try: | ||
max_waiting_time = int(max_waiting_time) | ||
except Exception: | ||
status = 400 | ||
msg = "'max_waiting_time' must be a base-10 integer" | ||
resp = Response(dumps({'msg': msg}), status=status, mimetype=mimetype) | ||
return resp | ||
else: | ||
max_waiting_time = 45 | ||
|
||
if max_overlap_time is not None: | ||
try: | ||
max_overlap_time = int(max_overlap_time) | ||
except Exception: | ||
status = 400 | ||
msg = "'max_overlap_time' must be a base-10 integer" | ||
resp = Response(dumps({'msg': msg}), status=status, mimetype=mimetype) | ||
return resp | ||
else: | ||
max_overlap_time = 5 | ||
|
||
|
||
gms_url = 'http://google-movies-scraper.herokuapp.com/movies' | ||
gms_params = { | ||
'near': location, | ||
'date': days_from_now | ||
} | ||
|
||
# should definitely build some logic to handle response code of r... | ||
r = requests.get(gms_url, params=gms_params) | ||
theatres_json = loads(r.text) | ||
output = [] | ||
for theatre in theatres_json: | ||
try: | ||
tmp_theatre = Theatre(name=theatre.get('name'), | ||
program=theatre.get('program'), | ||
address=theatre.get('address')) | ||
|
||
tmp_json = tmp_theatre.to_json(max_waiting_time=max_waiting_time, | ||
max_overlap_time=max_overlap_time) | ||
|
||
output.append(tmp_json) | ||
except TypeError as e: | ||
warn(str(e)) | ||
|
||
status = 200 | ||
resp = Response(dumps(output), status=status, mimetype=mimetype) | ||
return(resp) | ||
|
||
|
||
if (__name__ == '__main__'): | ||
app.run(debug=True, host='0.0.0.0', port=5000) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from dairy_queen.doubledip import DoubleDip | ||
from dairy_queen.movie import Movie | ||
|
||
class TestDoubleDip: | ||
def test_to_json(self): | ||
|
||
doubledip = DoubleDip([ | ||
Movie(name='a', runtime=60, showtime='12:45'), | ||
Movie(name='b', runtime=120, showtime='14:00') | ||
]) | ||
|
||
json_output = [ | ||
{ | ||
'movie': 'a', | ||
'length': 60, | ||
'startTime': '12:45', | ||
'endTime': '13:45' | ||
}, | ||
{ | ||
'movie': 'b', | ||
'length': 120, | ||
'startTime': '14:00', | ||
'endTime': '16:00' | ||
} | ||
] | ||
|
||
assert doubledip.to_json() == json_output |
2 changes: 1 addition & 1 deletion
2
dairy_queen/tests/test_flatlist.py → ..._queen/dairy_queen/tests/test_flatlist.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from doubledip import FlatList | ||
from dairy_queen.doubledip import FlatList | ||
|
||
class TestFlatList: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
py==1.4.31 | ||
pytest==2.8.5 | ||
wheel==0.29.0 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
from setuptools import setup | ||
|
||
setup(name='dairy_queen', | ||
version='1.0.0', | ||
version='0.1.0', | ||
description='package to calculate double dips in a given theatre', | ||
url='http://github.com/stevenpollack/dairy_queen', | ||
author='Steven Pollack', | ||
author_email='[email protected]', | ||
setup_requires = ['pytest-runner'], | ||
tests_require = ['pytest'], | ||
setup_requires=['pytest-runner'], | ||
tests_require=['pytest'], | ||
license='MIT', | ||
classifiers=[ | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3" | ||
], | ||
packages=['dairy_queen'], | ||
zip_safe=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
-e git+https://github.com/stevenpollack/dairy_queen.git@heroku_app#egg=dairy_queen&subdirectory=dairy_queen | ||
Flask==0.10.1 | ||
gunicorn==19.4.5 | ||
iron-cache==0.3.2 | ||
iron-core==1.2.0 | ||
itsdangerous==0.24 | ||
Jinja2==2.8 | ||
MarkupSafe==0.23 | ||
py==1.4.31 | ||
pytest==2.8.5 | ||
wheel==0.29.0 | ||
python-dateutil==2.5.0 | ||
requests==2.9.1 | ||
six==1.10.0 | ||
Werkzeug==0.11.4 |