34 lines
942 B
Python
34 lines
942 B
Python
from flask import Flask, request, jsonify
|
|
import requests, re, json, os, yaml
|
|
from db import *
|
|
from aliexpress import *
|
|
|
|
app = Flask(__name__)
|
|
|
|
def get_conf():
|
|
'''return settings in settings.yaml file'''
|
|
with open(os.path.dirname(os.path.realpath(__file__))+"/settings.yaml", 'r') as conf_file:
|
|
settings = yaml.safe_load(conf_file)
|
|
return settings
|
|
|
|
@app.route('/')
|
|
def hello_world():
|
|
return 'Hello, World!'
|
|
|
|
@app.route('/datahistory',methods = ['POST', 'GET'])
|
|
def data_history_request():
|
|
if request.method == 'GET':
|
|
print("fetching data history")
|
|
settings = get_conf()
|
|
return jsonify(get_history(settings["db"]))
|
|
|
|
@app.route('/dataitem',methods = ['POST', 'GET'])
|
|
def data_item_request():
|
|
if request.method == 'GET':
|
|
print("fetching data item")
|
|
settings = get_conf()
|
|
return jsonify(get_item(settings["db"]))
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug = True)
|