From 9f55cf48a3bd20761b7f0a54d505be662e181083 Mon Sep 17 00:00:00 2001 From: Jose De Freitas Date: Tue, 2 Mar 2021 14:37:11 -0500 Subject: [PATCH] Change folder structure --- voter/Procfile | 2 +- voter/api/__init__.py | 0 voter/log.txt | 1 - voter/{api/api.py => main.py} | 27 ++++++++++++++++++++++----- voter/server.py | 23 ----------------------- 5 files changed, 23 insertions(+), 30 deletions(-) delete mode 100644 voter/api/__init__.py delete mode 100644 voter/log.txt rename voter/{api/api.py => main.py} (83%) delete mode 100644 voter/server.py diff --git a/voter/Procfile b/voter/Procfile index f89c536..dc46f1b 100644 --- a/voter/Procfile +++ b/voter/Procfile @@ -1 +1 @@ -web: gunicorn server:app \ No newline at end of file +web: gunicorn main:app \ No newline at end of file diff --git a/voter/api/__init__.py b/voter/api/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/voter/log.txt b/voter/log.txt deleted file mode 100644 index 3cf20d5..0000000 --- a/voter/log.txt +++ /dev/null @@ -1 +0,0 @@ -- \ No newline at end of file diff --git a/voter/api/api.py b/voter/main.py similarity index 83% rename from voter/api/api.py rename to voter/main.py index 41b1151..ba6f0e5 100644 --- a/voter/api/api.py +++ b/voter/main.py @@ -1,21 +1,34 @@ import json from datetime import datetime -from flask import Blueprint, request, jsonify, make_response +from flask import Flask, jsonify, make_response, request +from flask_limiter import Limiter +from flask_limiter.util import get_remote_address + +app = Flask(__name__) + +limiter = Limiter( + app, + key_func=get_remote_address, + default_limits=["1200 per day", "50 per hour"] +) with open("data.json", "r", encoding="utf8") as read_data: channels = json.load(read_data) -api_channels = Blueprint('api_channels', __name__) + +@app.route("/") +def main(): + return "Awesome YouTubers voting system website." -@api_channels.route("/channels/all") +@app.route("/channels/all") def list_channels(): """ Lists all channels in the database. """ return jsonify(channels) -@api_channels.route("/channels/") +@app.route("/channels/") def get_channel(channel): """ If no query specified, prints the name of the @@ -55,7 +68,7 @@ def get_channel(channel): return "Channel not found on the list." -@api_channels.route("/channels//image.svg") +@app.route("/channels//image.svg") def img_channel(channel): """ Returns the YouTube score in a svg image. """ @@ -83,3 +96,7 @@ def img_channel(channel): return response else: return "Channel not found on the list" + + +if __name__ == "__main__": + app.run() diff --git a/voter/server.py b/voter/server.py deleted file mode 100644 index d995408..0000000 --- a/voter/server.py +++ /dev/null @@ -1,23 +0,0 @@ -from flask import Flask -from api.api import api_channels -from flask_limiter import Limiter -from flask_limiter.util import get_remote_address - -app = Flask(__name__) - -limiter = Limiter( - app, - key_func=get_remote_address, - default_limits=["1200 per day", "50 per hour"] -) - -app.register_blueprint(api_channels) - - -@app.route("/") -def main(): - return "Awesome YouTubers voting system website." - - -if __name__ == "__main__": - app.run()