mirror of
https://github.com/JoseDeFreitas/awesome-youtubers.git
synced 2024-10-01 01:06:03 -04:00
Add log function
This commit is contained in:
parent
7c98a15263
commit
82fff5b2d2
@ -1,4 +1,5 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
from flask import Blueprint, request, jsonify
|
||||
|
||||
with open("data.json", "r", encoding="utf8") as read_data:
|
||||
@ -27,6 +28,7 @@ def get_channel(channel):
|
||||
vote = str(request.args["vote"])
|
||||
|
||||
if channel in channels:
|
||||
# Adds/substracts 1 from the channel.
|
||||
if vote == "upvote":
|
||||
channels[channel] += 1
|
||||
elif vote == "downvote":
|
||||
@ -34,9 +36,15 @@ def get_channel(channel):
|
||||
else:
|
||||
return "Vote word not recognised."
|
||||
|
||||
# Write to database file.
|
||||
with open("data.json", "w", encoding="utf8") as write_data:
|
||||
json.dump(channels, write_data, indent=4)
|
||||
|
||||
# Write to log file.
|
||||
with open("log.txt", "a") as append:
|
||||
today = datetime.today().strftime('%Y-%m-%d-%H:%M')
|
||||
append.write(f"\n{vote.title()}d {channel} on {today}")
|
||||
|
||||
return f"You {vote}d successfully the channel {channel}."
|
||||
else:
|
||||
return "Channel not found on the list."
|
||||
|
@ -1,10 +1,10 @@
|
||||
{
|
||||
"Tech With Tim": 0,
|
||||
"Tech With Tim": 2,
|
||||
"Derek Banas": 0,
|
||||
"Don Jones": 0,
|
||||
"Corey Schafer": 0,
|
||||
"Brian Will": 0,
|
||||
"LearningLad": 0,
|
||||
"LearningLad": -1,
|
||||
"David Bombal": 0,
|
||||
"Ben Eater": 0,
|
||||
"The Coding Train": 0,
|
||||
|
1
voter/log.txt
Normal file
1
voter/log.txt
Normal file
@ -0,0 +1 @@
|
||||
-
|
@ -16,7 +16,7 @@ app.register_blueprint(api_channels)
|
||||
|
||||
@app.route("/")
|
||||
def main():
|
||||
return "Working"
|
||||
return "Awesome YouTubers voting system website."
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user