Exemple #1
0
 def __next__(self):
     nextdir = self.pratdir.__next__()
     pratfile = os.path.join(self.ydir, nextdir, "pratica.json")
     try:
         prat = tb.jload(pratfile)
     except tb.TableException:
         prat = {}
     return prat
Exemple #2
0
def showdata(nprat):
    "Visualizza dati di una pratica"
    if nprat:
        print()
        year = input_anno()
        basedir = namebasedir(year, nprat)
        dati_pratica = tb.jload((basedir, PRAT_JFILE))
        pprint(dati_pratica, indent=4)
    else:
        print()
        print("Errore numero pratica:", nprat)
Exemple #3
0
def main():
    "Procedura"
    if "-h" in sys.argv:
        print(__doc__)
        sys.exit()

    cfile_name = os.path.join(DATADIR, "config.json")
    cfile_save = os.path.join(DATADIR, "config.save")

    if os.path.exists(cfile_name):
        old_config = jload(cfile_name)
    else:
        old_config = {}

    if "-c" in sys.argv:
        creadirs()
        old_sede = old_config.get("sede", {})
        if not isinstance(old_sede, dict):
            old_sede = {}

        new_sede = ask_dict(SEDE, old_sede)
        new_params = ask_dict(PARAMS, old_config)
        new_tech = ask_dict(TECH, old_config)

        new_config = {"sede": new_sede}
        new_config.update(new_params)
        new_config.update(new_tech)
        new_config["flask_key"] = ftools.randstr(30)

        print()
        print()
        if old_config:
            os.rename(cfile_name, cfile_save)
        jsave(cfile_name, new_config)

        if old_config:
            print("La configurazione precedente si trova nel file:",
                  cfile_save)
        print("Creata nuova configurazione:", cfile_name)
    else:
        if old_config:
            show(old_config, cfile_name)
        else:
            print()
            print("Configurazione non definita. Usa '-h' per istruzioni")
            print()
Exemple #4
0
 def __init__(
         self,
         thedir,
         fname,  # pylint: disable=R0913
         year=None,
         directory_filter=lambda x: True,
         filename_filter=lambda x: True,
         content_filter=lambda x: True,
         sort=None,
         extract=None):
     self.years = get_years(thedir)  # Rendi noto quali altri
     self.years.sort()  # anni sono disponibili
     if is_year(year):
         self.year = str(year)
     else:
         self.year = str(thisyear())
     ydir = os.path.join(thedir, self.year)
     self.records = []
     self.errors = []
     try:
         pdirs = [x for x in os.listdir(ydir) if IS_PRAT_DIR.match(x)]
     except FileNotFoundError:
         pdirs = []
     else:
         pdirs = [
             os.path.join(ydir, x) for x in pdirs if directory_filter(x)
         ]
         pdirs.sort()
     for pdir in pdirs:
         fnm = os.path.join(pdir, fname)
         if filename_filter(fnm):
             try:
                 rec = tb.jload(fnm)
             except tb.TableException:
                 self.errors.append(fnm)
                 continue
             if rec and content_filter(rec):
                 if extract:
                     rec = {
                         key: value
                         for key, value in rec.items() if key in extract
                     }
                 self.records.append(rec)
     if sort:
         self.records.sort(key=sort)
Exemple #5
0
def testlogin():
    "Test funzionamento login"
    print('Prova userid/password')
    userid = input("Userid: ")
    psw = getpass()
    thedir = checkdir()
    config = tb.jload((thedir, 'config.json'))
    ldap_host = config.get("ldap_host", "-")
    ldap_port = config.get("ldap_port", 0)
    try:
        update_userlist()
    except Exception:
        print()
        print("Lista utenti non accessibile\n")
        return
    ret, why = authenticate(userid, psw, ldap_host, ldap_port)
    if ret:
        print(' - Accesso: OK [%s]' % why)
    else:
        print(' - Accesso: NO [%s]' % why)
Exemple #6
0
def _find_max_field(what, year=None):
    "Cerca il massimo valore del campo specificato (della forma: nnn/yyyy)"
    if not year:
        year = thisyear()
    if not isinstance(what, (list, tuple)):
        what = (what, )
    yys = '%d' % year
    dpath = os.path.join(DATADIR, yys)
    try:
        plist = os.listdir(dpath)
    except Exception:
        plist = []
    maxfld = 0
    prat = ''
    for nprat in plist:
        path = os.path.join(dpath, nprat)
        try:
            dati_pratica = tb.jload((path, 'pratica.json'))
        except tb.TableException:
            logging.error("Errore lettura pratica %s", path)
            continue
        for item in what:
            value = dati_pratica.get(item)
            try:
                nnyy = value.split('/')
            except Exception:
                continue
            if len(nnyy) == 2:
                try:
                    nvalue = int(nnyy[0])
                except Exception:
                    continue
                else:
                    if maxfld < nvalue:
                        maxfld = nvalue
                        prat = nprat
    return maxfld, prat
Exemple #7
0
from logging.handlers import RotatingFileHandler, SMTPHandler
import requests
import ftools
from table import jload

__author__ = 'Luca Fini'
__version__ = '3.0.2'
__date__ = '21/8/2019'

IDENT = "EMAIL_FETCHER. Vers. %s. %s, %s" % (__version__, __author__, __date__)

DATADIR = ftools.datapath()
WORKDIR = ftools.workpath()

LOGFILE = os.path.join(WORKDIR, 'email_fetcher.log')
CONFIG = jload((DATADIR, 'config.json'))


def make_url(code):
    "Genera la URL per invio autorizzazione"
    return "http://{}:{}/email_approv/{}".format(CONFIG["web_host"],
                                                 CONFIG["web_port"], code)


def send_http(code, sender, mailhost):
    "Invio richiesta HTTP per approvazione"
    header = {
        'Identity': 'Email-Fetcher',
        'Sender-Email': sender,
        'Mail-Host': mailhost
    }