Commit 627e2689 authored by Jed Simson's avatar Jed Simson

Restructure directory into API and frontend sections

parent 9e3addb7
from flask import Blueprint, request, jsonify, render_template
from slider import Slider
from lib.slider import Slider
import time
main = Blueprint('main', __name__)
api = Blueprint('api', __name__, url_prefix='/api')
slider = Slider()
@main.route('/')
@api.route('/')
def index():
return jsonify({'name:': 'Reddit Slider',
'description': 'A simple program to allow greater filtering options for Reddit submissions.',
'version': 1.0})
@main.route('/search/')
def search():
return render_template('search.html')
@main.route('/search/<subreddit>/')
@api.route('/search/<subreddit>/')
def subreddit(subreddit):
dimension = request.args.get('range', None)
delta = request.args.get('delta', None)
......
from flask import Flask
from routes import main
from api.views import api
from slider.views import slider
def create_app():
app = Flask(__name__)
app.register_blueprint(main)
app.register_blueprint(api)
app.register_blueprint(slider)
return app
......
from praw import Reddit
from praw.errors import HTTPException
from praw.errors import HTTPException, InvalidSubreddit
import time
class Search:
def __init__(self):
......@@ -72,10 +71,12 @@ class Search:
limit=limit,
syntax='cloudsearch',
sort=sort))
except HTTPException as exc:
except HTTPException as e:
time.sleep(backoff)
backoff *= 2
pass
except InvalidSubreddit as e:
raise ValueError('Invalid Subreddit provided... Subreddit probably does not exist.')
search_results = [s for s in results
if original_lowest_timestamp <= s.created and
......
......@@ -5,7 +5,7 @@ from datetime import datetime
import timestring
from search import Search
from .search import Search
search = Search()
......@@ -51,14 +51,18 @@ class Slider:
# i.e. start of the current day -> end of the current day.
start, end = self.todays_dimensions
except timestring.TimestringInvalid as e:
raise ValueError('Invalid range given...')
raise ValueError('Unable to parse range given...')
print('Fetching {} `{}` submissions from /r/{} between {} and {}...'.format(limit, sort, subreddit, start, end))
generator = search.generate(subreddit,
try:
generator = search.generate(subreddit,
start,
end,
sort=sort,
limit=limit)
except ValueError as e:
raise e
submissions = [{'info': str(s), 'timestamp': int(s.created_utc),
'href': s.permalink,
......
from flask import Blueprint, request, render_template
slider = Blueprint('slider', __name__)
@slider.route('/')
@slider.route('/search/')
def index():
return render_template('search.html')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment