mirror of
https://github.com/JoseDeFreitas/awesome-youtubers.git
synced 2024-12-22 05:45:08 -05:00
Add update database system
This commit is contained in:
parent
3863384afe
commit
f9c62c2420
@ -1,7 +1,7 @@
|
||||
import json
|
||||
from flask import Blueprint, request, jsonify
|
||||
|
||||
with open("data.json", "r") as read_data:
|
||||
with open("data.json", "r", encoding="utf8") as read_data:
|
||||
channels = json.load(read_data)
|
||||
|
||||
api_channels = Blueprint('api_channels', __name__)
|
||||
@ -14,19 +14,27 @@ def list_channels():
|
||||
return jsonify(channels)
|
||||
|
||||
|
||||
@api_channels.route("/channels", methods=["GET", "POST"])
|
||||
@api_channels.route("/channels")
|
||||
def get_channel():
|
||||
"""
|
||||
Opens the confirmation form that sends the vote
|
||||
to the database corresponding the channel selected.
|
||||
"""
|
||||
|
||||
if "name" in request.args:
|
||||
if "name" in request.args and "vote" in request.args:
|
||||
name = str(request.args["name"])
|
||||
vote = str(request.args["vote"])
|
||||
else:
|
||||
return "No name of channel provided."
|
||||
return "No name of channel and vote provided."
|
||||
|
||||
if name in channels:
|
||||
return "Good!"
|
||||
if vote == "upvote":
|
||||
channels[name] += 1
|
||||
else:
|
||||
channels[name] -= 1
|
||||
|
||||
with open("data.json", "w", encoding="utf8") as write_data:
|
||||
json.dump(channels, write_data, indent=4)
|
||||
return f"You {vote}d successfully the channel {name}."
|
||||
else:
|
||||
return "The name specified is not a channel on the list."
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"Tech With Tim": 0,
|
||||
"Tech With Tim": 1,
|
||||
"Derek Banas": 0,
|
||||
"Don Jones": 0,
|
||||
"LearningLad": 0
|
||||
"LearningLad": -1
|
||||
}
|
Loading…
Reference in New Issue
Block a user