Skip to content

Commit

Permalink
999999999_10263485.py (#42, #2): able to infer basic CSV (not COD-AB …
Browse files Browse the repository at this point in the history
…original yet)
  • Loading branch information
fititnt committed May 19, 2022
1 parent fb187ec commit ea84b73
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 20 deletions.
56 changes: 46 additions & 10 deletions officinam/999999999/0/999999999_7200235.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

# l999999999_0 = __import__('999999999_0')
from L999999999_0 import (
csv_imprimendo,
hxltm_carricato,
qhxl_hxlhashtag_2_bcp47,
XLSXSimplici
Expand Down Expand Up @@ -268,10 +269,20 @@ def make_args(self, hxl_output=True):
default=None
)

# silentium, n, s, nominativus, en.wiktionary.org/wiki/silentium#Latin
parser.add_argument(
'--silentium',
help='Instead of exception with error message, output nothing',
metavar="silentium",
dest="silentium",
action='store_const',
const=True,
default=False
)
parser.add_argument(
# '--venandum-insectum-est, --debug',
'--venandum-insectum-est', '--debug',
help='Habilitar depuração? Informações adicionais',
help='Enable debug? Show extra informations',
metavar="venandum_insectum",
dest="venandum_insectum",
action='store_const',
Expand Down Expand Up @@ -324,16 +335,41 @@ def execute_cli(self, pyargs, stdin=STDIN, _stdout=sys.stdout,
if pyargs.methodus == 'xlsx_ad_csv':
xlsx = XLSXSimplici(_infile)
if not pyargs.ordines or \
not xlsx.de(pyargs.ordines[0]):
raise ValueError(
'--methodus [{0}] --ordines [{1}] [{2}] <{3}>'.format(
pyargs.methodus,
pyargs.ordines,
_infile,
xlsx.meta(),
))
not xlsx.de(pyargs.ordines[0]):

if pyargs.silentium:
return self.EXIT_OK
caput = ['#status+error', '#meta+item', '#meta+value']
data = [
['ERROR', '--methodus', pyargs.methodus],
['ERROR', '--ordines', str(pyargs.ordines)],
['ERROR', 'input', _infile],
['ERROR', 'xlsx.meta', xlsx.meta()],
]
# data = [[
# 'ERROR',
# '--methodus [{0}] --ordines [{1}] [{2}] <{3}>'.format(
# pyargs.methodus,
# pyargs.ordines,
# _infile,
# xlsx.meta(),
# )
# ]]
csv_imprimendo(data, caput)
return self.EXIT_ERROR
# raise ValueError(
# '--methodus [{0}] --ordines [{1}] [{2}] <{3}>'.format(
# pyargs.methodus,
# pyargs.ordines,
# _infile,
# xlsx.meta(),
# ))
xlsx.praeparatio()
data, caput = xlsx.imprimere()
# print(type(caput), caput)
# print(type(data), data)
csv_imprimendo(data, caput)

print(json.dumps(xlsx.meta()))
xlsx.finis()
return self.EXIT_OK

Expand Down
82 changes: 72 additions & 10 deletions officinam/999999999/0/L999999999_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@
import csv
import re
import sys
import datetime
from typing import Type

from openpyxl import load_workbook
from openpyxl import (
load_workbook
)

# pylint --disable=W0511,C0103,C0116 ./999999999/0/L999999999_0.py


def csv_imprimendo(data: list, caput: list = None, delimiter: str = ',',
archivum_trivio: str = None):
def csv_imprimendo(
data: list, caput: list = None, delimiter: str = ',',
archivum_trivio: str = None):
if archivum_trivio:
raise NotImplementedError('{0}'.format(archivum_trivio))
# imprimendō, v, s, dativus, https://en.wiktionary.org/wiki/impressus#Latin
Expand Down Expand Up @@ -166,7 +170,13 @@ class XLSXSimplici:

archivum_trivio: str = ''
workbook: None
sheet_active: str = None
active: str = None
active_col_start: int = 0
active_col_end: int = 1
active_col_ignore: list = [] # Example: headers without text
active_row_start: int = 0
active_row_end: int = 1
_formatum: str = 'csv'

def __init__(self, archivum_trivio: str) -> None:
"""__init__
Expand All @@ -176,7 +186,12 @@ def __init__(self, archivum_trivio: str) -> None:
"""
# from openpyxl import load_workbook
self.archivum_trivio = archivum_trivio
self.workbook = load_workbook(archivum_trivio, read_only=True)
self.workbook = load_workbook(
archivum_trivio, data_only=True, read_only=True)
# self.workbook = load_workbook(
# archivum_trivio, data_only=True)

self.workbook.iso_dates = True
self.sheet_active = None
# pass

Expand All @@ -185,10 +200,10 @@ def de(self, worksheet_reference: str = None) -> bool:
len(worksheet_reference) == 1:
meta = self.meta()
if worksheet_reference in meta['sheet_cod_ab']:
self.sheet_active = meta['sheet_cod_ab'][worksheet_reference]
self.active = meta['sheet_cod_ab'][worksheet_reference]
return True
if worksheet_reference in self.workbook:
self.sheet_active = worksheet_reference
self.active = worksheet_reference
return True
return False

Expand Down Expand Up @@ -227,7 +242,7 @@ def finis(self) -> None:
# https://en.wiktionary.org/wiki/finis#Latin
self.workbook.close()

def imprimere(self, formatum: str = 'csv') -> list:
def imprimere(self, formatum: str = None) -> list:
"""imprimere /print/@eng-Latn
Trivia:
Expand All @@ -238,9 +253,56 @@ def imprimere(self, formatum: str = 'csv') -> list:
formatum (str, optional): output format. Defaults to 'csv'.
Returns:
[list]:
[list]: data, caput
"""
caput = []
data = []
if formatum:
self._formatum = formatum

fons = self.workbook[self.active]

for row_index, row in enumerate(fons.rows):
if row_index >= self.active_row_start and \
row_index <= self.active_row_end:
linea = []
for col_index in range(
self.active_col_start, self.active_col_end -1):
textum = row[col_index].value

if textum:
if isinstance(textum, datetime.datetime):
textum = str(textum).replace(' 00:00:00', '')
linea.append(textum)
else:
linea.append('')

if len(caput) == 0:
caput = linea
else:
data.append(linea)
# a_dict[row[0].value+','+row[1].value].append(str(row[2].value))

return data, caput

def praeparatio(self):
"""praeparātiō
Trivia:
- praeparātiō, s, f, Nom., https://en.wiktionary.org/wiki/praeparatio
"""

self.active_col_end = self.workbook[self.active].max_column
self.active_row_end = self.workbook[self.active].max_row

fons = self.workbook[self.active]

for row_index, row in enumerate(fons.rows):
# TODO: discover where it starts
pass

# for index_cols in fons.rows

# @TODO: calculate if HXL, if have more columns than ideal, etc

return caput, data
return True

0 comments on commit ea84b73

Please sign in to comment.