Commit ea08a711 by Juan

ya anda el server

1 parent adeddc37
# -*- coding: <UTF8> -*-
import requests
import json
select = """SELECT dom.name as dominio, pf.create_date, pf.pfs_fecha, cli.name, cli.street, cli.street2, loc.name AS localidad, prov.name AS provincia, cli.zip AS codigo_postal, pais.name AS pais, pf.domicilio AS domicilio_pf FROM
(
(koozo_planillafosa AS pf LEFT JOIN account_invoice AS comp ON pf.pfs_acc_inv = comp.id)
LEFT JOIN
res_partner AS cli ON comp.partner_id = cli.id
LEFT JOIN
res_country_state AS prov ON prov.id = cli.state_id
LEFT JOIN
res_country AS pais ON pais.id = cli.country_id
LEFT JOIN
koozo_dominios AS dom ON dom.id = comp.ain_dom_id
LEFT JOIN
koozo_localidad AS loc ON loc.id = cli.par_loc_id OR loc.id = pf.pfs_loc_id
) WHERE pf."tws_Tipo" = 'cent' AND pf.create_date >= '01/01/2019 12:00:00 AM' AND pf.create_date <= '01/02/2020 12:00:00 AM'"""
titulos = ["DOMINIO", "DATETIME", "FECHA", "CLENTE", "CALLE", "CALLE2", "LOCALIDAD", "PROBINCIA", "COD POSTAL", "PAIS", "DOMICILIO"]
Configuracion = {"usuario": "administrador", "pass": "administrador", "puerto": 5432, "db": "isvareporte", "host": "127.0.0.1"}
parametros = {
"DBconf": Configuracion,
"Titulos": titulos,
"select" : select
}
var = json.dumps(parametros)
mpost = requests.post("http://127.0.0.1:11876/", data = var)
#mpost = requests.post("http://192.168.15.69:8080", data = var)
print(mpost.text)
\ No newline at end of file \ No newline at end of file
No preview for this file type
No preview for this file type
No preview for this file type
from Libmod.psql import BaseDatos
from Libmod.reporte import Reporte
import random
import string
class NegroReport():
def __init__(self):
self.__DBinit__()
self.ConfiguracionExecl()
def __DBinit__(self):
self.DB = BaseDatos()
self.DB.HOST = "127.0.0.1" #"192.168.10.59"
self.DB.PORT = 5432
self.DB.USER = "administrador"
self.DB.PASS = "administrador"
self.DB.DB = "isvareporte"
self.DB.SELECT = ""
def ConfiguradorDB(self, BaseDatos):
"""Aca gestionamos el objeto que se recive de falange para configurar
la db postgress usuario, db, puerto, pass, host enviados por falange"""
lista = {"usuario": self.DB.USER, "pass": self.DB.PASS,
"puerto": self.DB.PORT, "db": self.DB.DB, "host": self.DB.PORT}
for variable in lista.keys():
try:
lista[variable] = BaseDatos[variable]
except:
print("falta dato db se toma default")
def ConfiguracionExecl(self):
"""configuro la clase que genera el excel y almaseno el nombre del archivo"""
self.Excel = Reporte()
self.Archivo = "tmp/reporte{}.xlsx".format(self.randomString())
self.Excel.archivo = self.Archivo
def randomString(self, stringLength=10):
"""Generate a random string of fixed length """
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(stringLength))
def Encabezado(self, Reporte):
"""Trato de cargar el encabezado si este no es nulo sino"""
print("armador encabezado", Reporte["Titulos"])
try:
self.Excel.Encabesado = Reporte["Titulos"]
except:
self.Excel.Encabesado = []
def Generador(self):
self.DB.Leer()
self.Excel.QUERY = self.DB.resultado
self.Excel.ArmarLibro()
return(self.Archivo)
\ No newline at end of file \ No newline at end of file
...@@ -2,7 +2,7 @@ import psycopg2 ...@@ -2,7 +2,7 @@ import psycopg2
class BaseDatos(): class BaseDatos():
def __init__(self): def __init__(self):
self.HOST = "192.168.10.59" self.HOST = "127.0.0.1" #"192.168.10.59"
self.PORT = 5432 self.PORT = 5432
self.USER = "administrador" self.USER = "administrador"
self.PASS = "administrador" self.PASS = "administrador"
...@@ -25,7 +25,22 @@ class BaseDatos(): ...@@ -25,7 +25,22 @@ class BaseDatos():
self.resultado = self.cur.fetchall() self.resultado = self.cur.fetchall()
def __ValidarComando__(self): def __ValidarComando__(self):
return(True) i = True
select = self.SELECT.split(" ")
for palabra in select:
if palabra == "DROP":
i = False
if palabra == "UPDATE":
i = False
if palabra == "INCERT":
i = False
if palabra == "drop":
i = False
if palabra == "update":
i = False
if palabra == "incert":
i = False
return(i)
def Leer(self): def Leer(self):
if self.__ValidarComando__(): if self.__ValidarComando__():
......
...@@ -19,19 +19,34 @@ class Reporte(): ...@@ -19,19 +19,34 @@ class Reporte():
self.Hoja1 = self.Libro.add_worksheet("Totalizado") self.Hoja1 = self.Libro.add_worksheet("Totalizado")
def __escribir_linea__(self, datos, linea): def __escribir_linea__(self, datos, linea):
formato = self.Libro.add_format({'bg_color': '#e6ffff'})
mod = linea % 2
if mod > 0:
formato = self.Libro.add_format({'bg_color': '#ffe6ff'})
n = 0 n = 0
for dato in datos: for dato in datos:
celda = Reporte.COLUMNA[n] + linea celda = Reporte.COLUMNA[n] + str(linea)
self.Hoja1.write(celda, str(dato)) self.Hoja1.write(celda, str(dato), formato)
n = n + 1 n = n + 1
self.ancho = Reporte.COLUMNA[n]
def __escribir_global(self): def __escribir_global(self):
n = 2 n = 2
for query in self.QUERY: for query in self.QUERY:
self.__escribir_linea__(query, str(n)) self.__escribir_linea__(query, n)
n = n + 1 n = n + 1
self.alto = str(n)
def __ajuste__(self):
Pn = self.ancho + self.alto
#self.Hoja1.add_table("A1:"+Pn, {'autofilter': 0})
print(Pn)
def __encabesado__(self): def __encabesado__(self):
print(self.Encabesado)
if self.Encabesado == []:
print("me salto los titulos")
return()
n = 0 n = 0
for celda in self.Encabesado: for celda in self.Encabesado:
c = Reporte.COLUMNA[n] + "1" c = Reporte.COLUMNA[n] + "1"
...@@ -42,6 +57,7 @@ class Reporte(): ...@@ -42,6 +57,7 @@ class Reporte():
self.__generarLibro__() self.__generarLibro__()
self.__escribir_global() self.__escribir_global()
self.__encabesado__() self.__encabesado__()
self.__ajuste__()
self.fin() self.fin()
return(self.archivo) return(self.archivo)
......
No preview for this file type
from Libmod.psql import BaseDatos
from Libmod.reporte import Reporte
repo = Reporte()
db = BaseDatos()
db.SELECT = """SELECT dom.name as dominio, pf.create_date, pf.pfs_fecha, cli.name, cli.street, cli.street2, loc.name AS localidad, prov.name AS provincia, cli.zip AS codigo_postal, pais.name AS pais, pf.domicilio AS domicilio_pf FROM
(
(koozo_planillafosa AS pf LEFT JOIN account_invoice AS comp ON pf.pfs_acc_inv = comp.id)
LEFT JOIN
res_partner AS cli ON comp.partner_id = cli.id
LEFT JOIN
res_country_state AS prov ON prov.id = cli.state_id
LEFT JOIN
res_country AS pais ON pais.id = cli.country_id
LEFT JOIN
koozo_dominios AS dom ON dom.id = comp.ain_dom_id
LEFT JOIN
koozo_localidad AS loc ON loc.id = cli.par_loc_id OR loc.id = pf.pfs_loc_id
) WHERE pf."tws_Tipo" = 'cent' AND pf.create_date >= '01/01/2019 12:00:00 AM' AND pf.create_date <= '01/02/2020 12:00:00 AM'"""
db.Leer()
#query = db.resultado
repo.QUERY = db.resultado
repo.Encabesado = ["DOMINIO", "DATETIME", "FECHA", "CLENTE", "CALLE", "CALLE2", "LOCALIDAD", "PROBINCIA", "COD POSTAL", "PAIS", "DOMICILIO"]
repo.ArmarLibro()
\ No newline at end of file \ No newline at end of file
from Libmod.armador import NegroReport
from flask import Flask, send_file
from flask import request
from flask_restful import Resource, Api
from flask import jsonify
import json
import datetime
app = Flask(__name__)
api = Api(app)
class indice(Resource):
def get(self):
datetime_object = datetime.datetime.now()
print(datetime_object)
hora = str(datetime_object)
return({"hora":hora})
def post(self):
content = json.loads(request.data)
#print(content)
retorno = self.acciones(content)
return(retorno)
def acciones(self, content):
rep = NegroReport()
rep.ConfiguradorDB(content["DBconf"])
rep.Encabezado(content)
rep.DB.SELECT = content["select"]
return(rep.Generador())
class icono(Resource):
def get(self):
return send_file("imagen/icon.ico")
api.add_resource(indice, "/")
api.add_resource(icono, "/favicon.ico")
if __name__ == '__main__':
app.run(debug=False, port=11876, host="0.0.0.0")
\ No newline at end of file \ No newline at end of file
from Libmod.psql import BaseDatos
from Libmod.reporte import Reporte
repo = Reporte()
db = BaseDatos()
db.SELECT = """SELECT dom.name as dominio, pf.create_date, pf.pfs_fecha, cli.name, cli.street, cli.street2, loc.name AS localidad, prov.name AS provincia, cli.zip AS codigo_postal, pais.name AS pais, pf.domicilio AS domicilio_pf FROM
(
(koozo_planillafosa AS pf LEFT JOIN account_invoice AS comp ON pf.pfs_acc_inv = comp.id)
LEFT JOIN
res_partner AS cli ON comp.partner_id = cli.id
LEFT JOIN
res_country_state AS prov ON prov.id = cli.state_id
LEFT JOIN
res_country AS pais ON pais.id = cli.country_id
LEFT JOIN
koozo_dominios AS dom ON dom.id = comp.ain_dom_id
LEFT JOIN
koozo_localidad AS loc ON loc.id = cli.par_loc_id OR loc.id = pf.pfs_loc_id
) WHERE pf."tws_Tipo" = 'cent' '"""
db.Leer()
#query = db.resultado
repo.QUERY = db.resultado
repo.Encabesado = ["DOMINIO", "DATETIME", "FECHA", "CLENTE", "CALLE", "CALLE2", "LOCALIDAD", "PROBINCIA", "COD POSTAL", "PAIS", "DOMICILIO"]
repo.ArmarLibro()
\ No newline at end of file \ No newline at end of file
File mode changed
,juan,juan-ThinkPad-X230,24.02.2020 14:04,file:///home/juan/.config/libreoffice/4;
\ No newline at end of file \ No newline at end of file
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!