Apply full functionality

This commit is contained in:
Jose De Freitas 2021-02-28 17:52:08 -05:00
parent 7b25a80fd5
commit 81c064b6b6
2 changed files with 48 additions and 27 deletions

View File

@ -14,30 +14,51 @@ def list_channels():
return jsonify(channels) return jsonify(channels)
@api_channels.route("/channels") @api_channels.route("/channels/<channel>")
def get_channel(): def get_channel(channel):
""" if "vote" in request.args:
Opens the confirmation form that sends the vote
to the database corresponding the channel selected.
"""
if "name" in request.args and "vote" in request.args:
name = str(request.args["name"])
vote = str(request.args["vote"]) vote = str(request.args["vote"])
if "name" in request.args and "vote" not in request.args: if channel in channels:
return vote
# else:
# return "No name of channel and vote provided."
if name in channels:
if vote == "upvote": if vote == "upvote":
channels[name] += 1 channels[channel] += 1
elif vote == "downvote":
channels[channel] -= 1
else: else:
channels[name] -= 1 return "Vote word not recognised."
with open("data.json", "w", encoding="utf8") as write_data: with open("data.json", "w", encoding="utf8") as write_data:
json.dump(channels, write_data, indent=4) json.dump(channels, write_data, indent=4)
return f"You {vote}d successfully the channel {name}."
return f"You {vote}d successfully the channel {channel}."
else: else:
return "The name specified is not a channel on the list." return "Channel not found on the list."
else:
if channel in channels:
return "Channel: " + channel
else:
return "Channel not found on the list."
@api_channels.route("/channels/<channel>/image.svg")
def img_channel(channel):
if channel in channels:
return f"""
<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
width="52px" height="22px" viewBox="0 0 52 22" fill="none">
<style>
.text {{
font-family: "Segoe UI", Ubuntu, Sans-Serif;
font-weight: bold;
}}
</style>
<rect x="0.5" y="0.5" height="99%" width="51" fill="none"/>
<g>
<text x="5" y="17" fill="#00b4f0" class="text">
{channels[channel]}
</text>
</g>
</svg>
"""
else:
return "Channel not found on the list"

View File

@ -1,10 +1,10 @@
{ {
"Tech With Tim": 0, "Tech With Tim": 12,
"Derek Banas": 0, "Derek Banas": 1,
"Don Jones": 0, "Don Jones": 1,
"Corey Schafer": 0, "Corey Schafer": 0,
"Brian Will": 0, "Brian Will": 0,
"LearningLad": 0, "LearningLad": 68,
"David Bombal": 0, "David Bombal": 0,
"Ben Eater": 0, "Ben Eater": 0,
"The Coding Train": 0, "The Coding Train": 0,
@ -23,7 +23,7 @@
"WilliamFiset": 0, "WilliamFiset": 0,
"Caleb Curry": 0, "Caleb Curry": 0,
"CodingEntrepreneurs": 0, "CodingEntrepreneurs": 0,
"Sebastiaan Mathôt": 0, "Sebastiaan Math\u00f4t": 0,
"AngelSix": 0, "AngelSix": 0,
"DataDaft": 0, "DataDaft": 0,
"Fun Fun Function": 0, "Fun Fun Function": 0,