1 from lib.source import MeteoFrance
3 from configparser import ConfigParser
4 from logging.config import fileConfig
5 from logging import getLogger
6 from pathlib import Path
7 from shutil import rmtree
8 from subprocess import Popen, PIPE
11 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
16 def __init__(self, clean = False):
17 logger.info("Predictops engine launched")
20 print("Ne pas oublier d'exporter la BDD dans pgModeler")
21 print("Ni de copier l'archive dans la data")
24 # Cleaning the data directory
25 logger.info("Cleaning and restoring data directory")
26 directory = Path.cwd() / 'data'
27 if directory.is_dir():
29 p = Path(Path.cwd() / 'data')
32 # Cleaning the postgresql database
33 config = ConfigParser()
34 config.read((Path.cwd() / 'config') / 'main.cfg')
36 host = config['postgresql']['host']
37 user = config['postgresql']['user']
38 port = config['postgresql']['port']
39 dbname = config['postgresql']['dbname']
41 logger.info("PostgreSQL database deletion")
42 command = ['dropdb', '-h', host, '-U', user, '-p', port, dbname]
43 process = Popen(command, stdout=PIPE, stderr=PIPE)
46 logger.info("PostgreSQL database creation")
47 command = ['createdb', '-h', host, '-U', user, '-p', port, dbname]
48 process = Popen(command, stdout=PIPE, stderr=PIPE)
51 def add_meteofrance(self):
52 self.meteofrance = MeteoFrance()
56 engine = Engine(clean = False)
57 engine.add_meteofrance()