Package: eu-state-aids
Descriptioneu-state-aidsis a package to importstate aids related datafrom single countries sources
and produce CSV files, according to a common data structure.The tool provides both a Command Line Interface (theeu-state-aidscommand),
and an API. See theUsagesection.The common CSV format used for the export:NameTypeMeaningName of the beneficiaryStringThe name of the aid's beneficiaryID of the beneficiaryLong IntegerThe unique ID of the aid's beneficiaryEuropean operation program (ID)StringThe unique CCI code of the european program, see detailshereAmounts (€)Float with 2 digits precisionTotal amount of the project (in Euro)DateDateYYYY[-MM-DD]Date of the beginning of the aid program (at least the year)State aid SchemeStringThe aid scheme code. The format isSA.XXXXX, wher the Xs are digits.InstallationPython versions from 3.7 are supported.The package depends on these python packages:typeropenpyxlpandasrequestsvalidatorsSo, it's better to create avirtualenvbefore installation.The package is hosted on pypi, and can be installed, for example using pip:pip install eu-state-aidsUsageCommand Line InterfaceTheeu-state-aidsbinary command will be available after installation.
It offers help with:eu-state-aids --helpTheeu-state-aidscommand can be used to extract the data from the official sources,
and populate the CSV files.For each country, data files will firstly befetchedand stored locally,
and thereafterusedin order toexportCSV files.This two-step procedure is useful, since it is not always possible to download source files (Excel, XML, ...) from
BI systems of nation states, as it has been seen that they tend to time-out whenever the number of records is
high enough.The logic of these two phases can vary for each single european state, so each country will have a dedicated module,
that will be executable as a sub-command.BulgaryTo retrieve data and produce a CSV file for Bulgary (bg), 2015:eu-state-aids bg fetch 2015
  eu-state-aids bg export 2015To launch the scriptsfor all yearsfor Bulgary (bg):# download all years' excel files into local storage 
for Y in $(seq 2014 2022)
do 
  eu-state-aids bg fetch $Y
done

# process all years' excel files and export CSV records into local storage 
#./data/bg/$Y.csv files
for Y in $(seq 2014 2022)
do
  python  -m eu_state_aids bg export $Y
doneItalyItaly needs a slightly different procedure, as before invoking the fetch/export commands,
amisure.csvfile needs to be generated, so that all aids records found in XML files can be
compared with found CE_CODE and filtered.eu-state-aids bg generate_measuresTo retrieve data and produce a CSV file for Italy (it), 2015, there is actually no need to fetch the file,
as files have been copied on a reliable source.eu-state-aids bg export 2015 --delete-processedThis will generate a loop over all months of 2015, fetch the files, if they're not already fetched,
extract, transform and filter the records for each month and emit a CSV file with all the records found.
The amount of money is summed for each beneficiary (over all records in that year). The fetched file will be deleted
after the procedure, if required through the--delete-processedoption.To launch the scriptsfor all yearsfor Italy (it):# download all years' excel files into local storage 
for Y in $(seq 2014 2022)
do 
  eu-state-aids it export $Y --delete-processed
doneAPIThe fetch and export logics can be used from within a python program,
importing the packages. All options values must be explicited in API calls.from eu_state_aids import bg

for year in ['2015', '2016', '2017']:
  bg.fetch(year, local_path='./data/bg')
  bg.export(
    year, local_path='./data/bg', 
    stateaid_url="https://stateaid.minfin.bg/document/860", 
    program_start_year="2014"
  )Note on italian dataItalian government sources suffer from two issues.XML files are not automatically downloadable from single dedicated URLS, but must be downloaded manually,
as the softare solution adopted for the open data section of the web site does not allow such individual downloads.
They have been mirrored on apublic AWS resource,
and will be fetched from there.XML files have not been compressed and theOpenData_Aiuto_*.xmlfiles are huge (~1GB). Once compressed,
their size reduce to 1/25th of the original size. So they will be stored on the AWS mirror in zipped format.SupportThere is no guaranteed support available, but authors will try to keep up with issues
and merge proposed solutions into the code base.Project StatusThis project is funded by the European Commission and is currently (2021) under active developement.ContributingIn order to contribute to this project:verify that python 3.7+ is being used (or usepyenv)verify or installpoetry, to handle packages and dependencies in a leaner way,
with respect to pip and requirementsclone the projectgit clone git@github.com:openpolis/eu-state-aids.gitinstall the dependencies in the virtualenv, withpoetry install,
this will also install the dev dependenciesdevelop wildly, running tests and coverage withcoverage run -m pytestcreate apull requestwait for the maintainers to review and eventually merge your pull request into the main repositoryTestingTests are under the tests folder.requests-mockis used to mock requests to remote data files, in order to avoid slow remote connections during tests.AuthorsGuglielmo Celata -guglielmo@openpolis.itLicensingThis package is released under an MIT License, see details in the LICENSE.txt file.