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

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