mirror of
https://github.com/JoseDeFreitas/awesome-youtubers.git
synced 2024-12-22 13:55:08 -05:00
Change to SQLalchemy
This commit is contained in:
parent
ba8514bf02
commit
d4617d9569
@ -1,164 +0,0 @@
|
||||
{
|
||||
"Tech_With_Tim": 0,
|
||||
"Derek_Banas": 0,
|
||||
"Don_Jones": 0,
|
||||
"Corey_Schafer": 0,
|
||||
"Brian_Will": 0,
|
||||
"LearningLad": 0,
|
||||
"David_Bombal": 0,
|
||||
"Ben_Eater": 0,
|
||||
"The_Coding_Train": 0,
|
||||
"Geek's_Lesson": 0,
|
||||
"Intellipaat": 0,
|
||||
"ProgrammingKnowledge": 0,
|
||||
"Coding_Tech": 0,
|
||||
"Simplified_Coding": 0,
|
||||
"Smartherd": 0,
|
||||
"Tensor_Programming": 0,
|
||||
"freeCodeCamp.org": 0,
|
||||
"CS_Dojo": 0,
|
||||
"sentdex": 0,
|
||||
"Java_Brains": 0,
|
||||
"IAmTimCorey": 0,
|
||||
"WilliamFiset": 0,
|
||||
"Caleb_Curry": 0,
|
||||
"CodingEntrepreneurs": 0,
|
||||
"Sebastiaan_Math\u00f4t": 0,
|
||||
"AngelSix": 0,
|
||||
"DataDaft": 0,
|
||||
"Fun_Fun_Function": 0,
|
||||
"Mike_Dane": 0,
|
||||
"KodingKevin": 0,
|
||||
"The_Cherno": 0,
|
||||
"Hussein_Nasser": 0,
|
||||
"Alex_Lee": 0,
|
||||
"Redis_University": 0,
|
||||
"NeuralNine": 0,
|
||||
"Real_Python": 0,
|
||||
"LucidProgramming": 0,
|
||||
"Nick_Chapsas": 0,
|
||||
"Python_In_1_Minute": 0,
|
||||
"Andreas_Kling": 0,
|
||||
"Hackers_Realm": 0,
|
||||
"Bro_Code": 0,
|
||||
"NullPointer_Exception": 0,
|
||||
"dotNET": 0,
|
||||
"Codevolution": 0,
|
||||
"Flux": 0,
|
||||
"techsith": 0,
|
||||
"CSS_Animation": 0,
|
||||
"Dani_Krossing": 0,
|
||||
"JavaScript_Mastery": 0,
|
||||
"Omatum": 0,
|
||||
"Punit_Chawla": 0,
|
||||
"Dev_Ed": 0,
|
||||
"DesignCourse": 0,
|
||||
"Traversy_Media": 0,
|
||||
"Thomas_Bradley": 0,
|
||||
"Red_Stapler": 0,
|
||||
"Brian_Design": 0,
|
||||
"Fireship": 0,
|
||||
"Academind": 0,
|
||||
"Florin_Pop": 0,
|
||||
"LevelUpTuts": 0,
|
||||
"Programming_with_Mosh": 0,
|
||||
"LearnCode.academy": 0,
|
||||
"Raw_Coding": 0,
|
||||
"Layout_Land": 0,
|
||||
"The_Net_Ninja": 0,
|
||||
"Kevin_Powell": 0,
|
||||
"Harry_Wolff": 0,
|
||||
"Coding_Garden": 0,
|
||||
"Hitesh_Choudhary": 0,
|
||||
"swyx": 0,
|
||||
"Yuri_Artyukh": 0,
|
||||
"Jason_Lengstorf": 0,
|
||||
"DevTips": 0,
|
||||
"Online_Tutorials": 0,
|
||||
"Bitfumes": 0,
|
||||
"Web_Dev_Simplified": 0,
|
||||
"Ben_Awad": 0,
|
||||
"Ebenezer_Don": 0,
|
||||
"Zach_Star": 0,
|
||||
"Domain_of_Science": 0,
|
||||
"Neso_Academy": 0,
|
||||
"Computerphile": 0,
|
||||
"stanfordonline": 0,
|
||||
"FCIH_OCW": 0,
|
||||
"MIT_OpenCourseWare": 0,
|
||||
"Bob_Trenwith": 0,
|
||||
"Harvard's_CS50": 0,
|
||||
"3Blue1Brown": 0,
|
||||
"Socratica": 0,
|
||||
"Abhishek_Thakur": 0,
|
||||
"Ahlad_Kumar": 0,
|
||||
"Aladdin_Persson": 0,
|
||||
"Andreas_Mueller": 0,
|
||||
"Data_School": 0,
|
||||
"Henry_AI_Labs": 0,
|
||||
"Jeremy_Howard": 0,
|
||||
"Rasa": 0,
|
||||
"Yannic_Kilcher": 0,
|
||||
"OpenAI": 0,
|
||||
"Two_Minute_Papers": 0,
|
||||
"ScriptersWar": 0,
|
||||
"Brackeys": 0,
|
||||
"Jonas_Tyroller": 0,
|
||||
"RealTutsGML": 0,
|
||||
"Mark_Rise": 0,
|
||||
"Chris_Courses": 0,
|
||||
"Zenva": 0,
|
||||
"Mix_and_Jam": 0,
|
||||
"Sebastian_Lague": 0,
|
||||
"DaFluffyPotato": 0,
|
||||
"ChiliTomatoNoodle": 0,
|
||||
"GDQuest": 0,
|
||||
"HeartBeast": 0,
|
||||
"Meth_Meth_Method": 0,
|
||||
"Clear_Code": 0,
|
||||
"Professor_Messer": 0,
|
||||
"CodeCommand": 0,
|
||||
"LiveOverflow": 0,
|
||||
"NullByte": 0,
|
||||
"Hackersploit": 0,
|
||||
"Gerald_Auger": 0,
|
||||
"Network_Chuck": 0,
|
||||
"Net_VN": 0,
|
||||
"Network_Direction": 0,
|
||||
"NetworKing": 0,
|
||||
"PowerCert_Animated_Videos": 0,
|
||||
"Learn_Google_Spreadsheets": 0,
|
||||
"ICT_Tutorial_Channel": 0,
|
||||
"Online_Training_for_Everyone": 0,
|
||||
"Simon_Sez_IT": 0,
|
||||
"Tom_Scott": 0,
|
||||
"Riba_Linux": 0,
|
||||
"MSFT_WebCast": 0,
|
||||
"How_to_Graphic_Design": 0,
|
||||
"ArmaganVideos": 0,
|
||||
"T&T_Tutorials": 0,
|
||||
"Pixel_&_Bracket": 0,
|
||||
"Zakey_Design": 0,
|
||||
"Art_with_Flo": 0,
|
||||
"Envato_Tuts+": 0,
|
||||
"Logos_By_Nick": 0,
|
||||
"OBEDIA": 0,
|
||||
"Black_Mixture": 0,
|
||||
"Avnish_Parker": 0,
|
||||
"Deny_King": 0,
|
||||
"Blender_Guru": 0,
|
||||
"Grant_Abbitt": 0,
|
||||
"CG_Fast_Track": 0,
|
||||
"DUCKY_3D": 0,
|
||||
"Teaching_Tech": 0,
|
||||
"Linus_Tech_Tips": 0,
|
||||
"educ8s.tv": 0,
|
||||
"GreatScott!": 0,
|
||||
"RaspberryPiIVBeginners": 0,
|
||||
"ExplainingComputers": 0,
|
||||
"GCFLearnFree.org": 0,
|
||||
"mayuko": 0,
|
||||
"Joshua_Fluke": 0,
|
||||
"Joma_Tech": 0,
|
||||
"All_About_Electronics": 0
|
||||
}
|
@ -1,10 +1,19 @@
|
||||
import json
|
||||
import threading
|
||||
from flask import Flask, jsonify, make_response, request
|
||||
from flask import (
|
||||
Flask, jsonify,
|
||||
make_response, request,
|
||||
render_template
|
||||
)
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_limiter import Limiter
|
||||
from flask_limiter.util import get_remote_address
|
||||
|
||||
# App configuration
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///youtubers.sqlite3"
|
||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
limiter = Limiter(
|
||||
app,
|
||||
@ -12,11 +21,15 @@ limiter = Limiter(
|
||||
default_limits=["1200 per day", "50 per hour"]
|
||||
)
|
||||
|
||||
with open("data.json", "r", encoding="utf8") as read_data:
|
||||
channels = json.load(read_data)
|
||||
|
||||
lock = threading.Lock()
|
||||
|
||||
# Database model
|
||||
|
||||
class Channel(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String, unique=True, nullable=False)
|
||||
vote = db.Column(db.Integer, default=0, nullable=False)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
@ -28,7 +41,10 @@ def index():
|
||||
def list_channels():
|
||||
""" Lists all channels in the database. """
|
||||
|
||||
return jsonify(channels)
|
||||
return render_template(
|
||||
"all.html",
|
||||
channels=Channel.query.order_by(Channel.name).all()
|
||||
)
|
||||
|
||||
|
||||
@app.route("/channels/<channel>")
|
||||
@ -53,15 +69,12 @@ def get_channel(channel):
|
||||
return "Vote word not recognised."
|
||||
|
||||
# Write to database file.
|
||||
with lock:
|
||||
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 {channel}."
|
||||
else:
|
||||
return "Channel not found on the list."
|
||||
else:
|
||||
if channel in channels:
|
||||
if channel in Channel.query.order_by(Channel.name).all():
|
||||
return "Channel: " + channel
|
||||
else:
|
||||
return "Channel not found on the list."
|
||||
@ -71,7 +84,7 @@ def get_channel(channel):
|
||||
def img_channel(channel):
|
||||
""" Returns the YouTube score in a svg image. """
|
||||
|
||||
if channel in channels:
|
||||
if channel in Channel.query.order_by(Channel.name).all():
|
||||
svg_image = f"""
|
||||
<svg xmlns="http://www.w3.org/2000/svg" x="0px" y="0px"
|
||||
width="52px" height="22px" viewBox="0 0 52 22" fill="none">
|
||||
@ -98,4 +111,5 @@ def img_channel(channel):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
db.create_all()
|
||||
app.run(debug=True)
|
||||
|
14
src/voter/templates/all.html
Normal file
14
src/voter/templates/all.html
Normal file
@ -0,0 +1,14 @@
|
||||
{% extends base.html %}
|
||||
|
||||
{% block content %}
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Vote</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ channels.name }}</td>
|
||||
<td>{{ channels.vote }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
{% endblock %}
|
13
src/voter/templates/base.html
Normal file
13
src/voter/templates/base.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Awesome YouTubers</title>
|
||||
</head>
|
||||
<body>
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
BIN
src/voter/youtubers.sqlite3
Normal file
BIN
src/voter/youtubers.sqlite3
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user