-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mathieu <[email protected]>
- Loading branch information
1 parent
6f352fc
commit 7bfb9fa
Showing
1 changed file
with
35 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,50 @@ | ||
#!/usr/bin/env python | ||
|
||
from flask import Flask, jsonify, request | ||
from flask import Flask, jsonify, request, Response | ||
from sqlalchemy import create_engine, text, Table, select, MetaData, inspect, Column | ||
import time | ||
|
||
app = Flask(__name__) | ||
engine = create_engine('mysql://root:[email protected]:3305/area', echo=False) | ||
"""engine = create_engine('mysql://root:[email protected]:3305/area', echo=False) | ||
connection = engine.connect() | ||
metadata = MetaData() | ||
insp = inspect(engine) | ||
print(insp.get_table_names()) | ||
users = Table('users', metadata) | ||
query = select([users]) | ||
#print(query) | ||
#print(query)""" | ||
|
||
@app.route("/user") | ||
def users(): | ||
return | ||
class User: | ||
def __init__(self, name): | ||
self.name = name | ||
|
||
users = [] | ||
|
||
@app.route("/user", methods=['GET']) | ||
def get_users(): | ||
return jsonify([user.__dict__ for user in users]) | ||
|
||
@app.route("/user/<name>", methods=['GET']) | ||
def get_user(name): | ||
for user in users: | ||
if user.name == name: | ||
return jsonify(user.__dict__) | ||
return Response(status=404) | ||
|
||
@app.route("/user", methods=['POST']) | ||
def create_user(): | ||
name = request.json['name'] | ||
users.append(User(name)) | ||
return Response(status=200) | ||
|
||
@app.route("/user/<name>", methods=['DELETE']) | ||
def delete_user(name): | ||
for user in users: | ||
if user.name == name: | ||
users.remove(user) | ||
return Response(status=200) | ||
return Response(status=404) | ||
|
||
@app.route("/about.json") | ||
def about(): | ||
|
@@ -31,4 +58,5 @@ def about(): | |
} | ||
return jsonify(data) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(port=8000, debug=True) |