painel / app.py
Atualli's picture
Update app.py
4b32352 verified
raw
history blame
4.23 kB
import os
from datasets import load_dataset
import json
import uuid
from pathlib import Path
import json
from datasets import load_dataset
from flask import Flask, request, jsonify, Response
import requests
from flask_cors import CORS
from flask_apscheduler import APScheduler
import shutil
from PIL import Image
#import sqlite3
from huggingface_hub import Repository
import subprocess
import urllib.parse
app = Flask(__name__, static_url_path='/static')
CORS(app)
Path("static/images").mkdir(parents=True, exist_ok=True)
def update_repository():
print("Updating repository")
@ app.route('/operacao')
def index():
return app.send_static_file('operacao.html')
@ app.route('/operacaoTemplate.html')
def operacao():
return app.send_static_file('operacaoTemplate.html')
@ app.route('/testeface')
def testeface():
return app.send_static_file('testeface.html')
@ app.route('/getresource', methods=['GET'])
def getresource():
argr = request.args.get('r')
#return app.send_static_file(res)
newurl = 'http://painel.atualli.com/getresource?r='+argr
res = requests.get(newurl)
headers = [
(k,v) for k,v in res.raw.headers.items()
]
response = Response(res.content, res.status_code, headers)
return response
@ app.route('/novo-front/<file>')
def novofront(file):
return app.send_static_file('novo-front/'+file+'.html')
@ app.route('/novo-front/css/<file>')
def novofrontcss(file):
return app.send_static_file('novo-front/css/'+file)
@ app.route('/novo-front/img/<file>')
def novofrontimg(file):
return app.send_static_file('novo-front/img/'+file)
@ app.route('/autentica', methods=['GET'])
def autentica():
email = request.args.get('email')
passw = request.args.get('passw')
newurl = 'http://painel.atualli.com/autentica?email='+email+'&passw='+passw
res = requests.get(newurl)
response = Response(res.content, res.status_code, res.headers)
return response
@ app.route('/proxyimg', methods=['GET'])
def proxyimg():
newurl = request.args.get('img')
#newurl = "http://painel.atualli.com:8098/getcamera?c=12"
print(newurl)
res = requests.get(newurl)
print(res)
response = Response(res.content, res.status_code, res.headers)
return response
@ app.route('/getdatamosaico', methods=['GET'])
def getdatamosaico():
cliente = request.args.get('cliente')
operador = request.args.get('operador')
newurl = 'http://painel.atualli.com/getdatamosaico?cliente='+cliente+"&operador="+operador
res = requests.get(newurl)
response = Response(res.content, res.status_code, res.headers)
return response
@ app.route('/getdatalocal', methods=['GET'])
def getdatalocal():
comando = request.args.get('comando')
login = request.args.get('login')
newurl = 'http://painel.atualli.com/getdatalocal?comando='+comando+"&login="+login
res = requests.get(newurl)
response = Response(res.content, res.status_code, res.headers)
return response
@ app.route('/getpathvideo', methods=['GET'])
def getpathvideo():
video = request.args.get('c')
# new = urllib.parse.quote(video)
newurl = 'http://painel.atualli.com/getpathrecord?c='+video
print(newurl)
res = requests.get(newurl)
response = Response(res.content, res.status_code, res.headers,mimetype="video/mp4")
return response
@ app.route('/<file>' , methods=['GET'])
def fileget(file):
newurl = 'http://painel.atualli.com/'+file
#newurl = 'http://atualli.ddns.net:8088/'+file
res = requests.get(newurl)
headers = [
(k,v) for k,v in res.raw.headers.items()
]
print(headers)
response = Response(res.content, res.status_code, headers)
return response
if __name__ == '__main__':
mode = os.environ.get('FLASK_ENV', 'production')
print(mode)
dev = mode == 'development'
print("Starting scheduler -- Running Production")
scheduler = APScheduler()
scheduler.add_job(id='Update Dataset Repository',
func=update_repository, trigger='interval', hours=1)
scheduler.start()
app.run(host='0.0.0.0', port=int(
os.environ.get('PORT', 7860)), debug=True, use_reloader=dev)