2024-01-25 23:52:23 +01:00
|
|
|
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
|
|
|
|
|
2024-01-28 01:20:50 +01:00
|
|
|
@app.route('/init')
|
|
|
|
def init_db():
|
|
|
|
print("init")
|
|
|
|
settings = get_conf()
|
|
|
|
initialize(settings["db"])
|
|
|
|
return 'Hello, World!'
|
|
|
|
|
|
|
|
@app.route('/update')
|
|
|
|
def update_hist():
|
|
|
|
print("update")
|
|
|
|
settings = get_conf()
|
|
|
|
fill_db(settings["db"], check_items(settings["item"]))
|
2024-01-25 23:52:23 +01:00
|
|
|
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)
|