mirror of
https://github.com/JoseDeFreitas/awesome-youtubers.git
synced 2025-01-03 03:20:48 -05:00
Set request limits
This commit is contained in:
parent
f3b1cd3333
commit
2ea13da31a
@ -12,13 +12,10 @@ from flask_limiter.util import get_remote_address
|
|||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///youtubers.sqlite3"
|
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///youtubers.sqlite3"
|
||||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
||||||
|
|
||||||
db = SQLAlchemy(app)
|
db = SQLAlchemy(app)
|
||||||
|
|
||||||
limiter = Limiter(
|
limiter = Limiter(app, key_func=get_remote_address,)
|
||||||
app,
|
|
||||||
key_func=get_remote_address,
|
|
||||||
default_limits=["1200 per day", "50 per hour"]
|
|
||||||
)
|
|
||||||
|
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
|
|
||||||
@ -38,12 +35,14 @@ channels_names = [cname.name for cname in channels]
|
|||||||
# Routes
|
# Routes
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
|
@limiter.exempt
|
||||||
def index():
|
def index():
|
||||||
""" Main route of the website. """
|
""" Main route of the website. """
|
||||||
return "Awesome YouTubers voting system website."
|
return "Awesome YouTubers voting system website."
|
||||||
|
|
||||||
|
|
||||||
@app.route("/channels/all")
|
@app.route("/channels/all")
|
||||||
|
@limiter.exempt
|
||||||
def list_channels():
|
def list_channels():
|
||||||
""" Lists all channels in the database. """
|
""" Lists all channels in the database. """
|
||||||
|
|
||||||
@ -51,6 +50,7 @@ def list_channels():
|
|||||||
|
|
||||||
|
|
||||||
@app.route("/channels/<channel>")
|
@app.route("/channels/<channel>")
|
||||||
|
@limiter.limit("20 per minute")
|
||||||
def get_channel(channel):
|
def get_channel(channel):
|
||||||
"""
|
"""
|
||||||
If no query specified, prints the name of the
|
If no query specified, prints the name of the
|
||||||
@ -67,14 +67,13 @@ def get_channel(channel):
|
|||||||
# Adds/substracts 1 from the channel.
|
# Adds/substracts 1 from the channel.
|
||||||
if vote == "upvote":
|
if vote == "upvote":
|
||||||
cvote.vote += 1
|
cvote.vote += 1
|
||||||
|
db.session.commit()
|
||||||
elif vote == "downvote":
|
elif vote == "downvote":
|
||||||
cvote.vote -= 1
|
cvote.vote -= 1
|
||||||
|
db.session.commit()
|
||||||
else:
|
else:
|
||||||
return "Vote word not recognised."
|
return "Vote word not recognised."
|
||||||
|
|
||||||
# Write to database file.
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
return f"You {vote}d successfully the channel {channel}."
|
return f"You {vote}d successfully the channel {channel}."
|
||||||
else:
|
else:
|
||||||
return "Channel not found on the list."
|
return "Channel not found on the list."
|
||||||
@ -86,6 +85,7 @@ def get_channel(channel):
|
|||||||
|
|
||||||
|
|
||||||
@app.route("/channels/<channel>/image.svg")
|
@app.route("/channels/<channel>/image.svg")
|
||||||
|
@limiter.exempt
|
||||||
def img_channel(channel):
|
def img_channel(channel):
|
||||||
""" Returns the YouTube score in a svg image. """
|
""" Returns the YouTube score in a svg image. """
|
||||||
|
|
||||||
|
@ -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
|
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.
|
awesome content based on the community's opinion.
|
||||||
|
|
||||||
<img src="http://127.0.0.1:5000/channels/Don_Jones/image.svg">
|
<img src="awesome-youtubers.herokuapp.com/channels/Don_Jones/image.svg">
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user