mirror of
https://github.com/JoseDeFreitas/awesome-youtubers.git
synced 2025-03-12 01:56:34 -04:00
Add log function
This commit is contained in:
parent
7c98a15263
commit
82fff5b2d2
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
from datetime import datetime
|
||||||
from flask import Blueprint, request, jsonify
|
from flask import Blueprint, request, jsonify
|
||||||
|
|
||||||
with open("data.json", "r", encoding="utf8") as read_data:
|
with open("data.json", "r", encoding="utf8") as read_data:
|
||||||
@ -27,6 +28,7 @@ def get_channel(channel):
|
|||||||
vote = str(request.args["vote"])
|
vote = str(request.args["vote"])
|
||||||
|
|
||||||
if channel in channels:
|
if channel in channels:
|
||||||
|
# Adds/substracts 1 from the channel.
|
||||||
if vote == "upvote":
|
if vote == "upvote":
|
||||||
channels[channel] += 1
|
channels[channel] += 1
|
||||||
elif vote == "downvote":
|
elif vote == "downvote":
|
||||||
@ -34,9 +36,15 @@ def get_channel(channel):
|
|||||||
else:
|
else:
|
||||||
return "Vote word not recognised."
|
return "Vote word not recognised."
|
||||||
|
|
||||||
|
# Write to database file.
|
||||||
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)
|
||||||
|
|
||||||
|
# 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}."
|
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."
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"Tech With Tim": 0,
|
"Tech With Tim": 2,
|
||||||
"Derek Banas": 0,
|
"Derek Banas": 0,
|
||||||
"Don Jones": 0,
|
"Don Jones": 0,
|
||||||
"Corey Schafer": 0,
|
"Corey Schafer": 0,
|
||||||
"Brian Will": 0,
|
"Brian Will": 0,
|
||||||
"LearningLad": 0,
|
"LearningLad": -1,
|
||||||
"David Bombal": 0,
|
"David Bombal": 0,
|
||||||
"Ben Eater": 0,
|
"Ben Eater": 0,
|
||||||
"The Coding Train": 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("/")
|
@app.route("/")
|
||||||
def main():
|
def main():
|
||||||
return "Working"
|
return "Awesome YouTubers voting system website."
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user