mirror of
https://github.com/JoseDeFreitas/awesome-youtubers.git
synced 2024-12-22 13:55:08 -05:00
Implement post method
This commit is contained in:
parent
5e93e266e9
commit
3863384afe
0
voter/api/__init__.py
Normal file
0
voter/api/__init__.py
Normal file
32
voter/api/api.py
Normal file
32
voter/api/api.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import json
|
||||||
|
from flask import Blueprint, request, jsonify
|
||||||
|
|
||||||
|
with open("data.json", "r") as read_data:
|
||||||
|
channels = json.load(read_data)
|
||||||
|
|
||||||
|
api_channels = Blueprint('api_channels', __name__)
|
||||||
|
|
||||||
|
|
||||||
|
@api_channels.route("/channels/all")
|
||||||
|
def list_channels():
|
||||||
|
""" Lists all channels in the database. """
|
||||||
|
|
||||||
|
return jsonify(channels)
|
||||||
|
|
||||||
|
|
||||||
|
@api_channels.route("/channels", methods=["GET", "POST"])
|
||||||
|
def get_channel():
|
||||||
|
"""
|
||||||
|
Opens the confirmation form that sends the vote
|
||||||
|
to the database corresponding the channel selected.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if "name" in request.args:
|
||||||
|
name = str(request.args["name"])
|
||||||
|
else:
|
||||||
|
return "No name of channel provided."
|
||||||
|
|
||||||
|
if name in channels:
|
||||||
|
return "Good!"
|
||||||
|
else:
|
||||||
|
return "The name specified is not a channel on the list."
|
6
voter/data.json
Normal file
6
voter/data.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"Tech With Tim": 0,
|
||||||
|
"Derek Banas": 0,
|
||||||
|
"Don Jones": 0,
|
||||||
|
"LearningLad": 0
|
||||||
|
}
|
@ -1,7 +1,10 @@
|
|||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
from api.api import api_channels
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
app.register_blueprint(api_channels)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def main():
|
def main():
|
Loading…
Reference in New Issue
Block a user