Skip to main content

CIG Data Extractor

Questo repository contiene uno script Python e un eseguibile standalone per l'estrazione automatizzata di dati relativi ai CIG (Codice Identificativo Gara) dal portale dati.anticorruzione.it dell'Autorità Nazionale Anticorruzione (ANAC).

Lo strumento è progettato per recuperare i dati dettagliati di un CIG specifico e fornirli in due formati JSON: una versione grezza (direttamente dall'API) e una versione "light" con i dati annidati già parsificati per una maggiore leggibilità e usabilità.

Caratteristiche

  • Estrazione Dati CIG: Recupera informazioni complete per un CIG fornito.
  • Output JSON Grezzo: Salva la risposta JSON originale dell'API (<CIG_NUMBER>_raw.json).
  • Output JSON Light: Salva una versione elaborata del JSON, con i campi JSON annidati parsificati (<CIG_NUMBER>.json).
  • Eseguibile Autoconsistente: Permette l'esecuzione dello strumento su sistemi senza un ambiente Python installato.
  • Opzione di Output Personalizzata: Permette di specificare il percorso completo del file di output per il JSON light, con controllo di esistenza del file.

Requisiti

Per l'Eseguibile Autoconsistente

Nessun requisito aggiuntivo. L'eseguibile include tutte le dipendenze necessarie.

Per lo Script Python (se si esegue il .py)

  • Python 3.x
  • Libreria requests

Per installare la libreria requests:

pip install requests

Utilizzo

Utilizzo dell'Eseguibile Autoconsistente

  1. Scarica l'eseguibile dalla directory dist/ (o crealo seguendo le istruzioni di sviluppo).

  2. Apri un terminale e naviga nella directory dove si trova l'eseguibile.

  3. Esegui il comando, sostituendo <CIG_NUMBER> con il CIG desiderato. Puoi anche specificare il percorso completo del file di output per il JSON light con l'opzione -o o --output-path.

    ./get_cig_data_requests <CIG_NUMBER> [-o <OUTPUT_FILE_PATH>]
    

    Esempi:

    ./get_cig_data_requests 918052266A
    ./get_cig_data_requests 918052266A -o /tmp/my_cig_data.json
    

Utilizzo dello Script Python

  1. Assicurati di avere Python 3 e la libreria requests installati.

  2. Apri un terminale e naviga nella directory dove si trova lo script get_cig_data_requests.py.

  3. Esegui il comando, sostituendo <CIG_NUMBER> con il CIG desiderato. Puoi anche specificare il percorso completo del file di output per il JSON light con l'opzione -o o --output-path.

    python3 get_cig_data_requests.py <CIG_NUMBER> [-o <OUTPUT_FILE_PATH>]
    

    Esempi:

    python3 get_cig_data_requests.py 918052266A
    python3 get_cig_data_requests.py 918052266A -o /tmp/my_cig_data.json
    

Output

Dopo l'esecuzione, verranno creati due file JSON nella stessa directory (o un singolo file light al percorso specificato con -o):

  • <CIG_NUMBER>_raw.json: Contiene la risposta JSON grezza dall'API. Questo file viene salvato solo se non si specifica l'opzione -o.
  • <CIG_NUMBER>.json: Contiene una versione elaborata del JSON, con i campi annidati parsificati per una maggiore leggibilità. Se l'opzione -o è specificata, questo file verrà salvato al percorso indicato.

Esempio per CIG 918052266A:

  • 918052266A_raw.json
  • 918052266A.json

Ecco un estratto del file 918052266A.json (versione light):

{
    "template": "N/A",
    "stazione_appaltante": {
        "CF_AMMINISTRAZIONE_APPALTANTE": "05678721001",
        "CITTA": "ROMA",
        "CODICE_AUSA": "0000225258",
        "DENOMINAZIONE_AMMINISTRAZIONE_APPALTANTE": "AGENZIA NAZIONALE PER L ATTRAZIONE DEGLI INVESTIMENTI E LO SVILUPPO D IMPRESA S.P.A.",
        "DENOMINAZIONE_CENTRO_COSTO": "CENTRALE DI COMMITTENZA",
        "ID_CENTRO_COSTO": "33986B12-6680-4F38-AE62-C734375E3060",
        "INDIRIZZO": "VIA CALABRIA 46",
        "ISTAT_COMUNE": "012058091",
        "REGIONE": "LAZIO",
        "SEZIONE_REGIONALE": "SEZIONE REGIONALE CENTRALE"
    },
    "bando": {
        "CIG": "918052266A",
        "COD_ESITO": 1.0,
        "COD_MODALITA_REALIZZAZIONE": "17",
        "COD_STRUMENTO_SVOLGIMENTO": 5.0,
        "COD_TIPO_SCELTA_CONTRAENTE": "1",
        "CPV": [
            {
                "COD_CPV": "71315400-3",
                "DESCRIZIONE_CPV": "SERVIZI DI COLLAUDO E VERIFICA DI EDIFICI",
                "FLAG_PREVALENTE": 1
            }
        ],
        "DATA_COMUNICAZIONE_ESITO": "2023-07-07",
        "DATA_SCADENZA_OFFERTA": "2022-05-26",
        "DETTAGLIO_STATO": {
            "DATA_ULTIMO_PERFEZIONAMENTO": "2022-05-24"
        },
        "DURATA_PREVISTA": 1220.0,
        "ESITO": "AGGIUDICATA",
        "FLAG_ESCLUSO": 0,
        "FLAG_PREV_RIPETIZIONI": 0,
        "FLAG_URGENZA": 0,
        "IMPORTO_COMPLESSIVO_GARA": 23569628.59,
        "IMPORTO_LOTTO": 3987864.4,
        "IMPORTO_SICUREZZA": 0.0,
        "LUOGO_NUTS": "ITF6",
        "MODALITA_REALIZZAZIONE": "ACCORDO QUADRO",
        "N_LOTTI_COMPONENTI": "7",
        "NUMERO_GARA": "8519126",
        "OGGETTO_GARA": "PROCEDURA DI GARA APERTA AI SENSI DEGLI ARTT. 54 E 60 DEL D.LGS. N. 50/2016, DA REALIZZARSI MEDIANTE PIATTAFORMA TELEMATICA, PER LA CONCLUSIONE DI ACCORDI QUADRO CON PIU’ OPERATORI ECONOMICI PER L’AFFIDAMENTO DI LAVORI (OG1 – OG11) E SERVIZI DI INGEGNERIA E ARCHITETTURA (E.21 – E.06 – S.03 – IA.02 – IA.04) PER LA NUOVA EDIFICAZIONE, RISTRUTTURAZIONE E RIQUALIFICAZIONE DI EDIFICI PUBBLICI RESIDENZIALI E NON.",
        "OGGETTO_LOTTO": "ACCORDO QUADRO OG1 - OG11 - SUB - LOTTO PRESTAZIONALE 1 – SERVIZI DI DI COLLAUDO - LOTTO GEOGRAFICO: CALABRIA - SICILIA",
        "OGGETTO_PRINCIPALE_CONTRATTO": "SERVIZI",
        "SETTORE": "SETTORI ORDINARI",
        "STATO": "ATTIVO",
        "STRUMENTO_SVOLGIMENTO": "PROCEDURE SVOLTE ATTRAVERSO PIATTAFORME TELEMATICHE DI NEGOZIAZIONE ART.58",
        "TIPO_CIG": "ORDINARIO",
        "TIPO_SCELTA_CONTRAENTE": "PROCEDURA APERTA",
        "FLAG_PNRR_PNC": 1,
        "FLAG_QUOTE": "S"
    }
}

Sviluppo

Creazione dell'Eseguibile Autoconsistente

Per creare l'eseguibile standalone, assicurati di avere PyInstaller installato:

pip install pyinstaller

Quindi, esegui il seguente comando nella directory principale del progetto:

pyinstaller --onefile get_cig_data_requests.py

Questo creerà l'eseguibile nella directory dist/.

Pulizia dei File di Build

PyInstaller crea delle directory temporanee (build/) e un file .spec. Puoi rimuoverli con:

rm -rf build/ get_cig_data_requests.spec

Licenza

Questo progetto è rilasciato sotto licenza MIT. Vedi il file LICENSE per maggiori dettagli. (Nota: il file LICENSE non è incluso in questo esempio, ma è una buona pratica aggiungerlo).

Metadata

Release files for cig-data-extractor 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cig-data-extractor 0.2.4
File Size Uploaded
cig_data_extractor-0.2.4.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cig-data-extractor 0.2.4
File Interpreter ABI Platform
cig_data_extractor-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 17.4 kB

Release files / cig_data_extractor-0.2.4.tar.gz

Download URL cig_data_extractor-0.2.4.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
159f70366476d7e2d5de1718f440d7cdef5b0743a2642ffbfdba63f817642be2
BLAKE2b-256 checksum
How to use checksums
bc2e7bc93c6eda092c69e57a1bbb4e963f0d485bc1ede9f602eaacfc30127ae9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / cig_data_extractor-0.2.4-py3-none-any.whl

Download URL cig_data_extractor-0.2.4-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e49f49f52727cf2d1d31760e683e528c658f9f76982d4a22026b895fdc460ad5
BLAKE2b-256 checksum
How to use checksums
faf0a008012da96c8d1ba129780d7dd895137208a9b7adc9a9219ac84c8e1e01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

0.2.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page