]> AND Private Git Repository - predictops.git/blob - main.py
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Adding documentation
[predictops.git] / main.py
1 from lib.source import MeteoFrance
2
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
9
10
11 fileConfig((Path.cwd() / 'config') / 'logging.cfg')
12 logger = getLogger()
13
14
15 class Engine:
16     def __init__(self, clean = False):
17         logger.info("Predictops engine launched")
18         if clean:
19             self.clean()
20             print("Ne pas oublier d'exporter la BDD dans pgModeler")
21             print("Ni de copier l'archive dans la data")
22
23     def clean(self):
24         # Cleaning the data directory
25         logger.info("Cleaning and restoring data directory")
26         directory  = Path.cwd() / 'data'
27         if directory.is_dir():
28             rmtree(directory)
29         p = Path(Path.cwd() / 'data')
30         p.mkdir()
31
32         # Cleaning the postgresql database
33         config = ConfigParser()
34         config.read((Path.cwd() / 'config') / 'main.cfg')
35
36         host   = config['postgresql']['host']
37         user   = config['postgresql']['user']
38         port   = config['postgresql']['port']
39         dbname = config['postgresql']['dbname']
40
41         logger.info("PostgreSQL database deletion")
42         command = ['dropdb', '-h', host, '-U', user, '-p', port, dbname]
43         process = Popen(command, stdout=PIPE, stderr=PIPE)
44         process.communicate()
45
46         logger.info("PostgreSQL database creation")
47         command = ['createdb', '-h', host, '-U', user, '-p', port, dbname]
48         process = Popen(command, stdout=PIPE, stderr=PIPE)
49         process.communicate()
50
51     def add_meteofrance(self):
52         self.meteofrance = MeteoFrance()
53
54
55
56 engine = Engine(clean = False)
57 engine.add_meteofrance()
58 engine.meteofrance.update()
59 print(len(engine.meteofrance.dated_features))