|
|
@ -1,31 +1,63 @@ |
|
|
|
import os |
|
|
|
from flask import Flask, jsonify, send_from_directory |
|
|
|
import requests |
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
|
|
|
|
|
#we define the route / |
|
|
|
@app.route('/') |
|
|
|
def welcome(): |
|
|
|
# return a json |
|
|
|
return jsonify({'status': 'api working'}) |
|
|
|
#************************************************* |
|
|
|
#variables globales |
|
|
|
ident_paheko='hfdd76cxza_ro' |
|
|
|
pass_paheko='LQBOyfuYaYnhhYTwVPpGNg' |
|
|
|
url_paheko='https://kaz-paheko.kazkouil.fr' |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
|
|
|
|
@app.route('/favicon.ico') |
|
|
|
def favicon(): |
|
|
|
# return send_from_directory(os.path.join(app.root_path, 'static'),'favicon.ico') |
|
|
|
return '', 204 |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
|
|
|
|
@app.route('/hello') |
|
|
|
def hello(): |
|
|
|
return 'Hello, World' |
|
|
|
return 'Hello World !' |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
|
|
|
|
@app.route('/liste_orgas_paheko') |
|
|
|
def get_list_orgas_paheko(): |
|
|
|
return jsonify( |
|
|
|
{'nom court': 'toto'}, |
|
|
|
{'nom court': 'titi'} |
|
|
|
) |
|
|
|
@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' |
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
|
|
|
|
@app.route('/liste_users_paheko') |
|
|
|
def get_liste_users_paheko(): |
|
|
|
|
|
|
|
global ident_paheko, pass_paheko, url_paheko |
|
|
|
|
|
|
|
@app.route('/favicon.ico') |
|
|
|
def favicon(): |
|
|
|
return send_from_directory(os.path.join(app.root_path, 'static'),'favicon.ico') |
|
|
|
auth = (ident_paheko, pass_paheko) |
|
|
|
api_url = url_paheko + '/api/user/category/12.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 |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
|
|
|
@ -33,3 +65,6 @@ 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')) |
|
|
|
|
|
|
|
#************************************************* |
|
|
|
|
|
|
|