diff --git a/src/voter/main.py b/src/voter/main.py index acfe4a5..882a802 100644 --- a/src/voter/main.py +++ b/src/voter/main.py @@ -12,13 +12,10 @@ from flask_limiter.util import get_remote_address app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///youtubers.sqlite3" app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False + db = SQLAlchemy(app) -limiter = Limiter( - app, - key_func=get_remote_address, - default_limits=["1200 per day", "50 per hour"] -) +limiter = Limiter(app, key_func=get_remote_address,) lock = threading.Lock() @@ -38,12 +35,14 @@ channels_names = [cname.name for cname in channels] # Routes @app.route("/") +@limiter.exempt def index(): """ Main route of the website. """ return "Awesome YouTubers voting system website." @app.route("/channels/all") +@limiter.exempt def list_channels(): """ Lists all channels in the database. """ @@ -51,6 +50,7 @@ def list_channels(): @app.route("/channels/") +@limiter.limit("20 per minute") def get_channel(channel): """ If no query specified, prints the name of the @@ -67,14 +67,13 @@ def get_channel(channel): # Adds/substracts 1 from the channel. if vote == "upvote": cvote.vote += 1 + db.session.commit() elif vote == "downvote": cvote.vote -= 1 + db.session.commit() else: return "Vote word not recognised." - # Write to database file. - db.session.commit() - return f"You {vote}d successfully the channel {channel}." else: return "Channel not found on the list." @@ -86,6 +85,7 @@ def get_channel(channel): @app.route("/channels//image.svg") +@limiter.exempt def img_channel(channel): """ Returns the YouTube score in a svg image. """ diff --git a/src/voter/readme.md b/src/voter/readme.md index 133aa3a..6051e7d 100644 --- a/src/voter/readme.md +++ b/src/voter/readme.md @@ -32,4 +32,4 @@ video quality, coverage of the topics it explains, among others), but, of course so I think being able to receive opinions from all users is a good way to filter and have truly awesome content based on the community's opinion. - \ No newline at end of file + \ No newline at end of file diff --git a/src/voter/youtubers.sqlite3 b/src/voter/youtubers.sqlite3 index 84510d6..decd465 100644 Binary files a/src/voter/youtubers.sqlite3 and b/src/voter/youtubers.sqlite3 differ