Created
February 7, 2019 12:58
-
-
Save Riduidel/192ab9e90d2ac0403a3af7b41fb2af4a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| from flask import Flask | |
| from flask import jsonify | |
| from flask import request | |
| from json import JSONEncoder | |
| class MyEncoder(JSONEncoder): | |
| def default(self, o): | |
| return o.__dict__ | |
| app = Flask(__name__) | |
| app.json_encoder = MyEncoder | |
| class Match: | |
| def __init__(self, j1, j2, g): | |
| self.joueur1 = j1 | |
| self.joueur2 = j2 | |
| self.gagnant = g | |
| matches = [ | |
| Match("Nicolas", "Rémi", "Rémi"), | |
| Match("Sébastien", "Laetitia", "Laetitia") | |
| ] | |
| @app.route("/", methods=["GET"]) | |
| def match_list(): | |
| joueur = request.args.get('joueur', None) | |
| if joueur: | |
| filtered = [m for m in matches if m.joueur1==joueur or m.joueur2==joueur] | |
| return jsonify(filtered) | |
| else: | |
| return jsonify(matches) | |
| @app.route("/", methods=["POST"]) | |
| def add_match(): | |
| print ("json %s"%request.is_json) | |
| content = request.get_json() | |
| print ("content %s"%content) | |
| # matches.append(content) | |
| return "", 201 |
orphaner
commented
Feb 7, 2019
pour du yaml, ça ressemble sans les s (pourquoi ??!)
import yaml
yaml.load( ... )
yaml.dump( ... )
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment