Added example in readme. Fixed docstrings.

dev
Franco Masotti 2 years ago
parent 268b4bcc7c
commit df9148bf97
Signed by: frnmst
GPG Key ID: 24116ED85666780A
  1. 38
      README.rst
  2. 42
      fattura_elettronica_reader/api.py

@ -41,9 +41,47 @@ http://frnmst.github.io/fattura-elettronica-reader
API examples
------------
fattura-elettronica-reader has a `public API`_.
This means for example that you can you easily read invoice files within another
Python program:
::
>>> import fattura_elettronica_reader
>>> data = {
'patched': True,
'configuration file': str(),
'write default configuration file': str(),
'extract attachments': True,
'metadata file': 'myfile.xml',
'invoice xslt type': 'ordinaria',
'no invoice xml validation': False,
'force invoice schema file download': False,
'generate html output': True,
'invoice filename': str(),
'no checksum check': False,
'force invoice xml stylesheet file download': False,
'ignore attachment extension whitelist': False,
'ignore attachment filetype whitelist': False,
'ignore signature check': False,
'ignore signers certificate check': False,
'force trusted list file download': False,
'keep original file': True,
}
>>> fattura_elettronica_reader.assert_data_structure(source='invoice', file_type='p7m', data=data)
>>> fattura_elettronica_reader.pipeline(
source='invoice',
file_type='p7m',
data=data,
)
Have a look at the `archive_invoice_files <https://raw.githubusercontent.com/frnmst/automated-tasks/master/src/archiving/archive_invoice_files.py>`_
script in the `automated tasks <https://github.com/frnmst/automated-tasks>`_ repository.
.. _public API: https://frnmst.github.io/fattura-elettronica-reader/api.html
CLI helps
---------

@ -610,7 +610,23 @@ def load_configuration(configuration_file: str):
def assert_data_structure(source: str, file_type: str, data: dict):
r"""Check the data structure."""
r"""Check the data structure.
:param source: the type of document to be considered.
Choose between ``invoice`` and ``generic``.
:param file_type the type of file to be considered:
Choose between ``p7m`` and ``plain``, depending on the
source parameter.
:param data: a data structure containing all the fields.
:type source: str
:type file_type: str
:type data: dict
:returns: None
:rtype: None
:raises: AssertionError
"""
# Check if file_type is coherent with source.
ok = False
assert source in ['invoice', 'generic']
assert 'patched' in data
@ -660,8 +676,9 @@ def assert_data_structure(source: str, file_type: str, data: dict):
assert isinstance(data['ignore signers certificate check'], bool)
assert isinstance(data['force trusted list file download'], bool)
assert isinstance(data['keep original file'], bool)
ok = True
elif file_type == 'plain':
pass
ok = True
elif source == 'generic':
if file_type == 'p7m':
assert 'ignore signature check' in data
@ -680,12 +697,29 @@ def assert_data_structure(source: str, file_type: str, data: dict):
assert isinstance(data['p7m files'], list)
for p in data['p7m files']:
assert isinstance(p, str)
ok = True
if not ok:
raise AssertionError
def pipeline(source: str, file_type: str, data: dict):
r"""Run the pipeline."""
r"""Run the pipeline.
:param source: the type of document to be considered.
Choose between ``invoice`` and ``generic``.
:param file_type the type of file to be considered:
Choose between ``p7m`` and ``plain``, depending on the
source parameter.
:param data: a data structure containing all the fields.
:type source: str
:type file_type: str
:type data: dict
:returns: None
:rtype: None
"""
assert_data_structure(source, file_type, data)
# data must be patchedfor this function to work.
# data must be patched for this function to work.
assert data['patched']
project_name = 'fattura_elettronica_reader'

Loading…
Cancel
Save