summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosue Kouka <jkouka@entrouvert.com>2017-08-17 08:22:03 (GMT)
committerJosue Kouka <jkouka@entrouvert.com>2017-08-17 08:22:03 (GMT)
commite51f548c10a88acadf1732b03a8304ba33c0e804 (patch)
treeff69c671a806401e0c4d252bdb7ce09177770be6
parentd0368ac0f557db8e5a45d67f763830016b178a74 (diff)
downloadconcerto2chronoformat-e51f548c10a88acadf1732b03a8304ba33c0e804.zip
concerto2chronoformat-e51f548c10a88acadf1732b03a8304ba33c0e804.tar.gz
concerto2chronoformat-e51f548c10a88acadf1732b03a8304ba33c0e804.tar.bz2
add file extraction to /tmp
-rwxr-xr-xconcerto_2_chrono_format.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/concerto_2_chrono_format.py b/concerto_2_chrono_format.py
index b75d90c..0843929 100755
--- a/concerto_2_chrono_format.py
+++ b/concerto_2_chrono_format.py
@@ -21,6 +21,7 @@ import re
import csv
import sys
import json
+import zipfile
import datetime
import logging
from logging.config import dictConfig
@@ -105,9 +106,15 @@ def json_write_data(json_data, output):
return False
+def extract_zip_to_tmp(filename):
+ with zipfile.ZipFile(filename, 'r') as zipf:
+ zipf.extractall('/tmp/')
+
+
class ConcertoFormatter(object):
name = 'concerto'
- output_file = 'concerto.json'
+ output_file = '/tmp/concerto.json'
+ expected_file = '/tmp/extract_prcit_planning_creche.csv'
fieldnames = [
'ID_LIE', 'DAT_JOUR_TMP', 'HEU_DEBUT_TMP', 'HEU_FIN_TMP',
'NB_PLACESPOSS_TMP', 'NB_PLACESOCC_TMP', 'NB_PLACESRESFUT_TMP',
@@ -119,7 +126,8 @@ class ConcertoFormatter(object):
def format(self):
agendas = []
- data = csv_get_dict_data(self.filename, fieldnames=self.fieldnames)
+ extract_zip_to_tmp(self.filename)
+ data = csv_get_dict_data(self.expected_file, fieldnames=self.fieldnames)
for nursery, events in groupby(data, lambda x: x['LIB_NOM_LIE']):
nursery_slug = slugify(nursery)
agenda = {'slug': nursery_slug, 'label': unicode(nursery, errors='replace'),
@@ -143,7 +151,7 @@ class ConcertoFormatter(object):
if __name__ == "__main__":
if len(sys.argv) < 2:
- logger.error('Invalid agrument number: concerto_2_chrono_format.py <file>')
+ logger.error('Invalid agrument number: concerto_2_chrono_format.py <input>')
sys.exit(1)
filename = sys.argv[1]