|
|
@ -1,14 +1,13 @@ |
|
|
|
import os |
|
|
|
from flask import Flask, jsonify, send_from_directory |
|
|
|
import requests |
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
|
from flask import Flask, jsonify, send_from_directory |
|
|
|
from flasgger import Swagger |
|
|
|
from flask_restful import Api, Resource |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
#variables globales |
|
|
|
ident_paheko='hfdd76cxza_ro' |
|
|
|
pass_paheko='LQBOyfuYaYnhhYTwVPpGNg' |
|
|
|
url_paheko='https://kaz-paheko.kazkouil.fr' |
|
|
|
app = Flask(__name__) |
|
|
|
api = Api(app) |
|
|
|
swagger = Swagger(app) |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
|
|
|
@ -16,48 +15,203 @@ url_paheko='https://kaz-paheko.kazkouil.fr' |
|
|
|
def favicon(): |
|
|
|
# return send_from_directory(os.path.join(app.root_path, 'static'),'favicon.ico') |
|
|
|
return '', 204 |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
|
|
|
|
@app.route('/') |
|
|
|
def silence(): |
|
|
|
return '' |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
|
|
|
|
@app.route('/hello') |
|
|
|
def hello(): |
|
|
|
return 'Hello World !' |
|
|
|
# class HelloWorld(Resource): |
|
|
|
# def get(self): |
|
|
|
# """ |
|
|
|
# titre de la desc: Un simple HelloWorld |
|
|
|
# Détail de la desc.... |
|
|
|
# --- |
|
|
|
# parameters: [] |
|
|
|
# responses: |
|
|
|
# 200: |
|
|
|
# description: A simple message HelloWorld |
|
|
|
# 404: |
|
|
|
# description: Aie aie aie !!! |
|
|
|
# """ |
|
|
|
# return {'message': 'Hello World!'} |
|
|
|
# |
|
|
|
# api.add_resource(HelloWorld, '/hello') |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
#DANGER si on touche à l'indentation pour swagger, c'est cuit! |
|
|
|
|
|
|
|
# class Username(Resource): |
|
|
|
# def get(self, username): |
|
|
|
# """ |
|
|
|
# This examples uses FlaskRESTful Resource |
|
|
|
# It works also with swag_from, schemas and spec_dict |
|
|
|
# --- |
|
|
|
# parameters: |
|
|
|
# - in: path |
|
|
|
# name: username |
|
|
|
# type: string |
|
|
|
# required: true |
|
|
|
# responses: |
|
|
|
# 200: |
|
|
|
# description: A single user item |
|
|
|
# schema: |
|
|
|
# id: User |
|
|
|
# properties: |
|
|
|
# username: |
|
|
|
# type: string |
|
|
|
# description: The name of the user |
|
|
|
# default: Steven Wilson |
|
|
|
# """ |
|
|
|
# return {'username': username}, 200 |
|
|
|
# |
|
|
|
# api.add_resource(Username, '/username/<username>') |
|
|
|
|
|
|
|
@app.route('/liste_categories_paheko') |
|
|
|
def get_liste_categories_paheko(): |
|
|
|
|
|
|
|
global ident_paheko, pass_paheko, url_paheko |
|
|
|
#************************************************* |
|
|
|
|
|
|
|
auth = (ident_paheko, pass_paheko) |
|
|
|
api_url = url_paheko + '/api/user/categories' |
|
|
|
class Paheko_categories(Resource): |
|
|
|
def get(self): |
|
|
|
""" |
|
|
|
Titre: Récupérer les catégories Paheko |
|
|
|
Détail: avec le compteur associé |
|
|
|
--- |
|
|
|
parameters: [] |
|
|
|
responses: |
|
|
|
200: |
|
|
|
description: Liste des catégories Paheko |
|
|
|
schema: |
|
|
|
id: Categorie |
|
|
|
properties: |
|
|
|
categorie: |
|
|
|
type: int |
|
|
|
description: Nom de la catégorie |
|
|
|
default: Example Category |
|
|
|
404: |
|
|
|
description: oops |
|
|
|
""" |
|
|
|
global ident_paheko, pass_paheko, url_paheko |
|
|
|
|
|
|
|
auth = (ident_paheko, pass_paheko) |
|
|
|
api_url = url_paheko + '/api/user/categories' |
|
|
|
|
|
|
|
response = requests.get(api_url, auth=auth) |
|
|
|
|
|
|
|
if response.status_code == 200: |
|
|
|
data = response.json() |
|
|
|
return jsonify(data) |
|
|
|
else: |
|
|
|
return jsonify({'error': 'La requête a échoué'}), response.status_code |
|
|
|
|
|
|
|
response = requests.get(api_url, auth=auth) |
|
|
|
api.add_resource(Paheko_categories, '/paheko/user/categories') |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
|
|
|
|
if response.status_code == 200: |
|
|
|
data = response.json() |
|
|
|
return jsonify(data) |
|
|
|
else: |
|
|
|
return jsonify({'error': 'La requête a échoué'}), response.status_code |
|
|
|
class Paheko_users(Resource): |
|
|
|
def get(self,categorie): |
|
|
|
""" |
|
|
|
Titre: Afficher les membres d'une catégorie Paheko |
|
|
|
Détail: |
|
|
|
--- |
|
|
|
parameters: |
|
|
|
- in: path |
|
|
|
name: categorie |
|
|
|
type: string |
|
|
|
required: true |
|
|
|
responses: |
|
|
|
200: |
|
|
|
description: Liste des membres une catégorie Paheko |
|
|
|
schema: |
|
|
|
id: Categories |
|
|
|
properties: |
|
|
|
categorie: |
|
|
|
type: string |
|
|
|
description: Id de la catégorie |
|
|
|
default: 3 |
|
|
|
404: |
|
|
|
description: oops |
|
|
|
""" |
|
|
|
|
|
|
|
global ident_paheko, pass_paheko, url_paheko |
|
|
|
|
|
|
|
auth = (ident_paheko, pass_paheko) |
|
|
|
api_url = url_paheko + '/api/user/category/'+categorie+'.json' |
|
|
|
|
|
|
|
response = requests.get(api_url, auth=auth) |
|
|
|
|
|
|
|
if response.status_code == 200: |
|
|
|
data = response.json() |
|
|
|
return jsonify(data) |
|
|
|
else: |
|
|
|
return jsonify({'error': 'La requête a échoué'}), response.status_code |
|
|
|
|
|
|
|
api.add_resource(Paheko_users, '/paheko/user/category/<categorie>') |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
|
|
|
|
@app.route('/liste_users_paheko') |
|
|
|
def get_liste_users_paheko(): |
|
|
|
# @app.route('/user_paheko/<id>') |
|
|
|
# def get_user_paheko(id): |
|
|
|
# |
|
|
|
# global ident_paheko, pass_paheko, url_paheko |
|
|
|
# |
|
|
|
# auth = (ident_paheko, pass_paheko) |
|
|
|
# api_url = url_paheko + '/api/user/'+id |
|
|
|
# |
|
|
|
# response = requests.get(api_url, auth=auth) |
|
|
|
# |
|
|
|
# if response.status_code == 200: |
|
|
|
# data = response.json() |
|
|
|
# return jsonify(data) |
|
|
|
# else: |
|
|
|
# return jsonify({'error': 'La requête a échoué'}), response.status_code |
|
|
|
|
|
|
|
class Paheko_user(Resource): |
|
|
|
def get(self,numero): |
|
|
|
""" |
|
|
|
Titre: Afficher un membre de Paheko |
|
|
|
Détail: |
|
|
|
--- |
|
|
|
parameters: |
|
|
|
- in: path |
|
|
|
name: numero |
|
|
|
type: string |
|
|
|
required: true |
|
|
|
responses: |
|
|
|
200: |
|
|
|
description: Affiche un membre de Paheko |
|
|
|
schema: |
|
|
|
id: Membres |
|
|
|
properties: |
|
|
|
numero: |
|
|
|
type: string |
|
|
|
description: Id du membre |
|
|
|
default: 1 |
|
|
|
404: |
|
|
|
description: oops |
|
|
|
""" |
|
|
|
|
|
|
|
global ident_paheko, pass_paheko, url_paheko |
|
|
|
|
|
|
|
auth = (ident_paheko, pass_paheko) |
|
|
|
api_url = url_paheko + '/api/user/category/12.json' |
|
|
|
global ident_paheko, pass_paheko, url_paheko |
|
|
|
|
|
|
|
auth = (ident_paheko, pass_paheko) |
|
|
|
api_url = url_paheko + '/api/user/'+numero |
|
|
|
|
|
|
|
response = requests.get(api_url, auth=auth) |
|
|
|
|
|
|
|
if response.status_code == 200: |
|
|
|
data = response.json() |
|
|
|
return jsonify(data) |
|
|
|
else: |
|
|
|
return jsonify({'error': 'La requête a échoué'}), response.status_code |
|
|
|
|
|
|
|
response = requests.get(api_url, auth=auth) |
|
|
|
api.add_resource(Paheko_user, '/paheko/user/<numero>') |
|
|
|
|
|
|
|
if response.status_code == 200: |
|
|
|
data = response.json() |
|
|
|
return jsonify(data) |
|
|
|
else: |
|
|
|
return jsonify({'error': 'La requête a échoué'}), response.status_code |
|
|
|
# #************************************************* |
|
|
|
#variables globales |
|
|
|
ident_paheko='hfdd76cxza_ro' |
|
|
|
pass_paheko='LQBOyfuYaYnhhYTwVPpGNg' |
|
|
|
url_paheko='https://kaz-paheko.kazkouil.fr' |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
|
|
|
@ -65,6 +219,3 @@ if __name__ == '__main__': |
|
|
|
#define the localhost ip and the port that is going to be used |
|
|
|
# in some future article, we are going to use an env variable instead a hardcoded port |
|
|
|
app.run(host='0.0.0.0', port=os.getenv('PORT')) |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
|
|
|
|