Coverage for src/ensae_teaching_cs/data/datazips.py: 89%
27 statements
« prev ^ index » next coverage.py v7.1.0, created at 2023-04-28 06:23 +0200
« prev ^ index » next coverage.py v7.1.0, created at 2023-04-28 06:23 +0200
1# coding: utf-8
2"""
3@file
4@brief Data mostly for the first and second years.
5"""
6import os
7from pyquickhelper.loghelper import noLOG
8from pyensae.filehelper.decompress_helper import decompress_zip
11def anyzip(filename, local=True, cache_folder=".", multi=False,
12 fLOG=noLOG, **kwargs):
13 """
14 Any zip.
16 @param filename filename
17 @param local local data or web
18 @param cache_folder where to cache the data if downloaded a second time
19 @param fLOG logging function
20 @param multi multiple files
21 @param kwargs downloading arguments
22 @return filename (str)
23 """
24 if local:
25 this = os.path.abspath(os.path.dirname(__file__))
26 this = os.path.join(this, "zips", filename)
27 if not os.path.exists(this):
28 raise FileNotFoundError(this)
29 res = decompress_zip(this, whereTo=cache_folder, fLOG=fLOG)
30 if cache_folder is not None:
31 res = [os.path.join(cache_folder, _) for _ in res]
32 else:
33 import pyensae.datasource
34 this = pyensae.datasource.download_data(
35 filename, whereTo=cache_folder, fLOG=fLOG, **kwargs)
36 if cache_folder is not None:
37 res = [os.path.join(cache_folder, _) for _ in this]
38 else:
39 res = this
40 if isinstance(res, list):
41 return res if multi else res[0]
42 return res
45def besancon_df(local=True, cache_folder=".", fLOG=noLOG):
46 """
47 Retrieves ``Besancon.df.zip``.
49 @param local local data or web
50 @param cache_folder where to cache the data if downloaded a second time
51 @param fLOG logging function
52 @return filename (str)
53 """
54 return anyzip("besancon.df.txt.zip", local=local, cache_folder=cache_folder,
55 fLOG=fLOG, website="xdtd")
58def added(local=True, cache_folder=".", fLOG=noLOG):
59 """
60 Retrieves ``added.zip``.
62 @param local local data or web
63 @param cache_folder where to cache the data if downloaded a second time
64 @param fLOG logging function
65 @return filename (str)
66 """
67 return anyzip("added.zip", local=local, cache_folder=cache_folder, fLOG=fLOG)
70def deal_flow_espace_vert_2018_2019(local=True, cache_folder=".", fLOG=noLOG):
71 """
72 Retrieves ``deal_flow_espaces_verts_2018_2019.zip``.
73 The sources compiles two files from pages:
74 * `Deal flow des projets verts : projets notifiés et financés en 2018
75 <https://data.ademe.fr/datasets/jeu-de-donnees-deal-flow-2018>`_
76 * `Deal flow des projets verts - Projets financés en 2019 et investissements envisagés en 2019
77 <https://data.ademe.fr/datasets/jeu-de-donnees-deal-flow-2019>`_
78 See :ref:`dealflowespacevertrst`.
79 """
80 return anyzip("deal_flow_espaces_verts_2018_2019.zip", local=local,
81 cache_folder=cache_folder, multi=True, fLOG=fLOG)