Example #1
0
# -*- coding: utf-8 -*-
from pypxlib import Table
from datetime import datetime
import sys
#empleado = int(sys.argv[1])
#fecha = datetime.strptime(sys.argv[2], "%Y-%m-%d")
#justificante = int(sys.argv[3])
table = Table("/root/Autorizaciones.DB")
#table = Table("/mnt/servidorconta/ASISTMIL/Autorizaciones.DB")
#table.insert((empleado, fecha, justificante, ''))
i = 0
for row in table:
    print i, row
    i += 1
table.close()
Example #2
0
from pypxlib import Table
from datetime import datetime
import sys

fecha_inicio = datetime.strptime(sys.argv[1], "%Y-%m-%d")
fecha_fin = datetime.strptime(sys.argv[2], "%Y-%m-%d")

table = Table("/mnt/servidorconta/ASISTMIL/Incidencias.DB")
faltas = []
for i, row in enumerate(table):
    #data = [i+1,row.Empleado,row.Fecha,row.Entrada,row.Inicomida,row.Fincomida,row.Salida,row.Horario,row.Retardo,row.Anticipado,row.Comida,row.Extras,row.Total,row.Registros]
    fecha = datetime(row.Fecha.year, row.Fecha.month, row.Fecha.day)
    if fecha_inicio <= fecha <= fecha_fin:
        if row.Horario == 'FALTA':
            faltas.append(row)
print faltas
from pypxlib import Table
from csv import DictWriter
from glob import glob
from traceback import print_exc

names = glob('./*.db')
for name in names:
    table = Table(name, encoding='cp1251')
    try:
        with open(name[:-3] + '.csv', 'w', encoding='utf-8',
                  newline='') as file:
            fields = [a for a in table.fields if not a.startswith('Date')]
            writer = DictWriter(file, fields, extrasaction='ignore')
            writer.writeheader()
            for row in table:
                row2 = {key: row[key] for key in fields}
                writer.writerow(row2)
    except:
        print_exc()
    finally:
        table.close()
from pypxlib import Table
import psycopg2
import datetime

conn = psycopg2.connect(
    "dbname=offset21junio user=openerp password=zentella host=localhost")
cr = conn.cursor()

table = Table("/mnt/servidorconta/ASISTMIL/Autorizaciones.DB")
tup = []
for i, row in enumerate(table):
    data = [i + 1, row.Empleado, row.Fecha, row.Justificante, row.Folio]
    tup.append(data)
args_str = ','.join(cr.mogrify("(%s,%s,%s,%s,%s)", x) for x in tup)
cr.execute("truncate table asistmil_autorizaciones")
cr.execute(
    "insert into asistmil_autorizaciones(id,empleado,fecha,justificante,folio) values "
    + args_str)
conn.commit()
conn.close()
Example #5
0
from pypxlib import Table
import psycopg2
import datetime
from conf import get_conf

conn, cr, tpath = get_conf()

table = Table(tpath + "Asignacion.DB")
tup = []
for i, row in enumerate(table):
    if not row.Inicio:
        continue
    anio, semana, dia = row.Inicio.isocalendar()
    cr.execute(
        "select * from asistmil_asignaciones where emp=%s and semana=%s and anio=%s",
        (row.Registro, semana, anio))
    if not cr.fetchall():
        tup.append([i + 1, row.Registro, semana, anio, row.Secuencia])
if tup:
    args_str = ','.join(cr.mogrify("(%s,%s,%s,%s,%s)", x) for x in tup)
    cr.execute(
        "insert into asistmil_asignaciones(id, emp, semana, anio, secuencia) values "
        + args_str)
    conn.commit()
conn.close()
def f_post_new_records_into_api(api_url,
                                decode_with="",
                                last_sent_id=0,
                                log=False,
                                timeout=10):
    try:
        last_sent_id = int(last_sent_id)

        parse_table = Table("PRUCHODY.db")
        decoding_table = Table("OSOBY.db")

        found = False
        position_from_last_sent = 1

        last_record_id = len(parse_table) - 1
        last_pass = parse_table[last_record_id]

        if last_record_id == last_sent_id:
            if log:
                print("No new records found")
            return

        while not found:
            position = last_sent_id + position_from_last_sent
            current_pass = parse_table[position]

            if log:
                print("Current ID", current_pass.ID)
            if log:
                print("Last ID", last_sent_id)

            person = f_get_person_with_chip_id(decoding_table,
                                               current_pass[decode_with])

            if person is None:
                person = {"Prijmeni": "None", "Jmeno": "None"}

            payload = (
                '{"datetime": "%s", "studentName": "%s", "studentSurname": "%s", "recordId": "%s", "direction": "%s", "turniketId": "%s", "chipId": "%s"}'
                % (
                    current_pass["Cas"],
                    f_decode_laf(person["Jmeno"]),
                    f_decode_laf(person["Prijmeni"]),
                    current_pass["ID"],
                    current_pass["Druh"],
                    current_pass["Terminal"],
                    current_pass["CIP"],
                )).encode("utf-8")

            headers = {"content-type": "application/json"}

            response = requests.request("POST",
                                        url=API_URL,
                                        data=payload,
                                        headers=headers,
                                        timeout=10)
            print(current_pass)
            print(response)

            position_from_last_sent += 1
            if log:
                print("Inserted record")

            if current_pass["ID"] == last_pass["ID"]:
                found = True
                if log:
                    print("Last record found")
            elif (current_pass["ID"] - last_sent_id) > 5:
                found = True
                if log:
                    print(
                        "Maximum number of rows open. Closing them and restarting."
                    )

        parse_table.close()
        decoding_table.close()

    except Exception as e:
        if log:
            print(
                f"Unexpected error {{{e}}}. Couldn't insert new data. Trying again in {timeout} seconds."
            )
        parse_table.close()
        decoding_table.close()

    if log:
        print("Going to sleep", end="\n\n")
Example #7
0
#!/usr/bin/env python3.5
# -*- coding: utf-8 -*-

from pypxlib import Table

table = Table('07312000.db')
try:
    # Process the table...
	#Число записей
    print (len(table))
	#Одна запись
    row = table[60966]
    print (row)
	#Какие поля
	print (table.fields)
finally:
    table.close()

#Row(Date=datetime.date(2018, 8, 1), Time=46602726.0, Operation=u'\x02', S101=4100.0, D101=u'O', S110=3833.110107421875, D110=u'O', S111=278.0, D111=u'O', S102=267.89947509765625, D102=u'O', S115=3832.1005249023438, D115=u'O', S103=14.048476219177246, D103=u'O', S104=0.0, D104=u'O', S105=0.0, D105=u'O', S200=91.32957458496094, D200=u'O', S201=89.718, D201=u'O', S300=63.1493670886076, D300=u'O', S701=1.49515, D701=u'O', S702=1.86715, D702=u'O', S703=1.5001, D703=u'O', S705=1.71015, D705=u'O', S706=1.621, D706=u'O', S707=1.91515, D707=u'O', S708=0.73845, D708=u'O', S711=29.865, D711=u'O', S712=23.73267325, D712=u'O', S713=19.1019543, D713=u'O', S715=6.676995, D715=u'O', S716=14.721255, D716=u'O', S717=17.3914425, D717=u'O', S718=9.42497985, D718=u'O', S720=120.9142999, D720=u'O', S900=36.75, D900=u'O', S1300=-0.0001451378809869376, D1300=u'O', S1600=1.215, D1600=u'O', S1601=1.113, D1601=u'O', S1602=0.058, D1602=u'O', S1603=0.034, D1603=u'O', S1604=0.01, D1604=u'O', S1605=0.0, D1605=u'O', S1003=10.099234939492515, D1003=u'O', S1200=-0.02202643171806167, D1200=u'O', S50=0.0, D50=u'O', S51=85.07579886054, D51=u'O', S1001=7.366725973253933, D1001=u'O', S113=0.0, D113=u'E', S202=0.0, D202=u'O', S731=1.49515, D731=u'O', S732=1.86715, D732=u'O', S733=1.5001, D733=u'O', S734=0.0, D734=u'E', S735=1.71015, D735=u'O', S736=1.621, D736=u'O', S737=1.91515, D737=u'O', S738=0.73845, D738=u'O', S302=0.8302752293577982, D302=u'O')
Example #8
0
from pypxlib import Table
import psycopg2
import datetime
from conf import get_conf

conn, cr, tpath = get_conf()

print "Justificantes"
table = Table(tpath + "Justificantes.DB")
tup = []
cr.execute("select count(*) from asistmil_justificantes")
if cr.fetchone()[0] == 0:
    for i,row in enumerate(table):
        data = [i+1,row.Clave,row.Descripcion,row.Tiempo,row.Dia,row.Entrada,row.Salida]
        tup.append(data)
    if tup:
        args_str = ','.join(cr.mogrify("(%s,%s,%s,%s,%s,%s,%s)", x) for x in tup)
        cr.execute("insert into asistmil_justificantes(id,clave,descripcion,tiempo,dia,entrada,salida) values " + args_str)
else:
    for i,row in enumerate(table):
        cr.execute("select count(*) from asistmil_justificantes where clave=%s", (row.Clave,))
        if cr.fetchone()[0] == 0:
            cr.execute("insert into asistmil_justificantes(clave,descripcion,tiempo,dia,entrada,salida) values (%s,%s,%s,%s,%s,%s)",
                (row.Clave,row.Descripcion,row.Tiempo,row.Dia,row.Entrada,row.Salida))

print "Secuencias"
table = Table(tpath + "Secuencias.DB")
tup = []
cr.execute("select count(*) from asistmil_secuencias")
if cr.fetchone()[0] == 0:
    for i,row in enumerate(table):
def main(argv):

  try:
    opts, args = getopt.getopt(argv,"hi:o:c:x",["ifile=","ofile=","headers=","headershelp="])
  except getopt.GetoptError:
    print 'paradoxdbsplitter.py -i <inputfile> -o <outputfile>'
    sys.exit(2)
  for opt, arg in opts:
    if opt == '-h':
       print 'paradoxdbsplitter.py -i <inputfile> -o <outputfile> -c <headers(hola,adios,pepe)>'
       sys.exit()
    elif opt in ("-x", "--helpheaders"):
      headershelp = 1
    elif opt in ("-i", "--ifile"):
       inputfile = arg
    elif opt in ("-o", "--ofile"):
       outputfile = arg
    elif opt in ("-c", "--headers"):
       cabeceras = arg.split(",")

    # elif opt in ("-b", "--block"):
    #    bloque = arg

  bloque = 100000
  table = Table(inputfile)

  if 'headershelp' in locals():
    print(table[0])
    sys.exit()

  registros = len(table)
  print "Dimension filas tabla: %s." % registros
  print "Cantidad de registros por fichero: %d." % bloque
  print "Cabeceras que se van a usar: %s." % cabeceras
  print "Ruta del archivo: %s." % inputfile

  print registros
  print bloque
  print registros/bloque
  print math.ceil(registros/bloque)

  iteraciones = int(math.ceil(registros/bloque))

  print "Ficheros que se van a generar: %s." % iteraciones

  iteracion = 0

  for iteracion in range(0, iteraciones):

    print "iteracion numero %s" % iteracion
    with open(outputfile+"_parte_"+str(iteracion)+".csv", "wb") as csvfile:

        spamwriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
        # headers
        spamwriter.writerow(cabeceras)
	start = iteracion * bloque
	end = start + bloque
        if end > registros:
          end = registros

        for row in range(start, end):

          #print start
          spamwriter.writerow([table[row][s].encode('utf8') if type(table[row][s]) is unicode else table[row][s] for s in cabeceras])
Example #10
0
def main(argv):

    try:
        opts, args = getopt.getopt(
            argv, "hi:o:c:x", ["ifile=", "ofile=", "headers=", "headershelp="])
    except getopt.GetoptError:
        print('paradoxdbsplitter.py -i <inputfile> -o <outputfile>')
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print(
                'paradoxdbsplitter.py -i <inputfile> -o <outputfile> -c <headers(hola,adios,pepe)>'
            )
            sys.exit()
        elif opt in ("-x", "--helpheaders"):
            headershelp = 1
        elif opt in ("-i", "--ifile"):
            inputfile = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg
        elif opt in ("-c", "--headers"):
            cabeceras = arg.split(",")
            print(cabeceras)

        # elif opt in ("-b", "--block"):
        #    bloque = arg

    bloque = 100000
    table = Table(inputfile)

    if 'headershelp' in locals():
        fields = table.fields
        headers = []
        for f in fields:
            headers.append(f)
        #print(headers)
        cabeceras = headers
        #sys.exit()

    registros = len(table)
    print("Table rows: %s" % registros)
    print("Rows per file: %d" % bloque)
    print("File headers to be extracted: %s" % cabeceras)
    print("File (db) path: %s" % inputfile)

    #print (registros)
    #print (bloque)
    #print (registros/bloque)
    #print (math.ceil(registros/bloque))

    iteraciones = int(math.ceil(registros / bloque))

    print("File parts about to generate: %s" % iteraciones)

    iteracion = 0

    for iteracion in range(0, iteraciones):

        print("iteracion numero %s" % iteracion)
        with open(outputfile + "_parte_" + str(iteracion) + ".csv",
                  "w") as csvfile:
            print(csvfile)

            spamwriter = csv.writer(csvfile,
                                    delimiter=';',
                                    quotechar='|',
                                    quoting=csv.QUOTE_MINIMAL)
            # headers
            spamwriter.writerow(cabeceras)
            start = iteracion * bloque
            end = start + bloque
            if end > registros:
                end = registros

            for row in range(start, end):

                #print start
                # FIX encoding here
                # spamwriter.writerow([table[row][s].encode('utf8') if type(table[row][s]) is unicode else table[row][s] for s in cabeceras])
                spamwriter.writerow(table[row][s] for s in cabeceras)
Example #11
0
# -*- coding: utf-8 -*-
from pypxlib import Table
import psycopg2
import datetime
from conf import get_conf

conn, cr, tpath = get_conf()

print "Justificantes"
table = Table(tpath + "Justificantes.DB")
tup = []
cr.execute("select count(*) from asistmil_justificantes")
if cr.fetchone()[0] == 0:
    for i, row in enumerate(table):
        data = [
            i + 1, row.Clave, row.Descripcion, row.Tiempo, row.Dia,
            row.Entrada, row.Salida
        ]
        tup.append(data)
    if tup:
        args_str = ','.join(
            cr.mogrify("(%s,%s,%s,%s,%s,%s,%s)", x) for x in tup)
        cr.execute(
            "insert into asistmil_justificantes(id,clave,descripcion,tiempo,dia,entrada,salida) values "
            + args_str)
else:
    print "hay datos"
    for i, row in enumerate(table):
        print "Clave %s?" % row.Clave,
        cr.execute(
            "select count(*) from asistmil_justificantes where clave=%s",
Example #12
0
from pypxlib import Table
import psycopg2
import datetime

conn = psycopg2.connect("dbname=offset21junio user=openerp password=zentella host=localhost")
cr = conn.cursor()

table = Table("/mnt/servidorconta/ASISTMIL/Secuencias.DB")
tup = []
for i,row in enumerate(table):
    data = [i+1,row.Clave,row.Domingo,row.Lunes,row.Martes,row.Miercoles,row.Jueves,row.Viernes,row.Sabado,row.Descripcion]
    tup.append(data)
args_str = ','.join(cr.mogrify("(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", x) for x in tup)
cr.execute("insert into asistmil_secuencias(id,clave,domingo,lunes,martes,miercoles,jueves,viernes,sabado,descripcion) values " + args_str)
conn.commit()
conn.close()