mirror of
https://github.com/prise6/smart-iss-posts
synced 2024-05-05 23:23:11 +02:00
module iss
This commit is contained in:
parent
f71fae4267
commit
14ad2c0492
48
iss/data/DataBaseManager.py
Normal file
48
iss/data/DataBaseManager.py
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
class DataBaseManager:
|
||||||
|
|
||||||
|
def __init__(self, connexion, config):
|
||||||
|
self.conn = connexion
|
||||||
|
self.config = config
|
||||||
|
self.cursor = self.conn.cursor()
|
||||||
|
|
||||||
|
|
||||||
|
def createPicturesTable(self, force = False):
|
||||||
|
|
||||||
|
if force:
|
||||||
|
self.cursor.execute("DROP TABLE IF EXISTS `iss`.`pictures`;")
|
||||||
|
|
||||||
|
self.cursor.execute("""
|
||||||
|
CREATE TABLE `iss`.`pictures` (
|
||||||
|
`pictures_latitude` FLOAT(10, 6) NULL,
|
||||||
|
`pictures_longitude` FLOAT(10, 6 ) NULL ,
|
||||||
|
`pictures_id` VARCHAR( 15 ) PRIMARY KEY ,
|
||||||
|
`pictures_timestamp` TIMESTAMP NULL ,
|
||||||
|
`pictures_location` TEXT NULL
|
||||||
|
) ENGINE = MYISAM ;
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
def insertRowPictures(self, array):
|
||||||
|
|
||||||
|
sql_insert_template = "INSERT INTO `iss`.`pictures` (pictures_latitude, pictures_longitude, pictures_id, pictures_timestamp, pictures_location) VALUES (%s, %s, %s, %s, %s);"
|
||||||
|
|
||||||
|
self.cursor.executemany(sql_insert_template, array)
|
||||||
|
self.conn.commit()
|
||||||
|
|
||||||
|
return self.cursor.rowcount
|
||||||
|
|
||||||
|
def select(self, array):
|
||||||
|
sql = """
|
||||||
|
SELECT tmp.* FROM (
|
||||||
|
SELECT
|
||||||
|
COUNT(*) as nb,
|
||||||
|
pictures_location as location
|
||||||
|
|
||||||
|
FROM iss.pictures
|
||||||
|
GROUP BY pictures_location
|
||||||
|
) as tmp
|
||||||
|
ORDER BY nb DESC
|
||||||
|
"""
|
2
iss/data/database_init.py
Normal file
2
iss/data/database_init.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
8
iss/data/sync_collections.sh
Normal file
8
iss/data/sync_collections.sh
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
|
||||||
|
## synchroniser avec les images déjà collectées
|
||||||
|
|
||||||
|
rsync -rve ssh my-deblan:~/projets/ISS-HDEV-wallpaper/Collections/ ~/Projets/smart-iss-posts/data/raw/collections/
|
||||||
|
|
||||||
|
scp -v ssh my-deblan:~/projets/ISS-HDEV-wallpaper/history.txt ~/Projets/smart-iss-posts/data/raw/history/
|
22
iss/tools/config.py
Normal file
22
iss/tools/config.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import yaml
|
||||||
|
from dotenv import find_dotenv, load_dotenv
|
||||||
|
|
||||||
|
load_dotenv(find_dotenv())
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
|
||||||
|
def __init__(self, project_dir = os.getenv("PROJECT_DIR"), mode = os.getenv("MODE")):
|
||||||
|
|
||||||
|
self.project_dir = project_dir
|
||||||
|
self.mode = mode
|
||||||
|
|
||||||
|
with open(os.path.join(self.project_dir, 'config', 'config_%s.yaml' % (self.mode)), 'r') as ymlfile:
|
||||||
|
self.config = yaml.load(ymlfile)
|
||||||
|
|
||||||
|
def get(self, key):
|
||||||
|
return self.config[key]
|
||||||
|
|
Loading…
Reference in a new issue