From 3ec1a6963fd093217c328ad7ecda2f11eea26931 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Sun, 17 Apr 2022 23:28:47 +0200 Subject: [PATCH] Import towns csv --- create_db.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/create_db.py b/create_db.py index 625fbb8..bfc7bb1 100755 --- a/create_db.py +++ b/create_db.py @@ -44,7 +44,7 @@ def parse_args(): default='exports') parser.add_argument('--towns', help='town raw csv file (inside source follder)', - default='communes2021.csv') + default='commune2021.csv') parser.add_argument('--departments', help='departments raw csv file (inside source follder)', default='departement2021.csv') @@ -79,6 +79,15 @@ def create_department_csv(raw_file): return dep +def create_towns_csv(raw_file): + """ + Process department files + """ + towns = pd.read_csv(raw_file, + usecols=["COM","TYPECOM","NCC","LIBELLE","DEP"]) + return towns.loc[towns['TYPECOM'] == 'COM', ['COM','NCC', 'LIBELLE', 'DEP']] + + if __name__ == '__main__': args = parse_args() #logging.basicConfig(level=logging.DEBUG) @@ -104,4 +113,9 @@ if __name__ == '__main__': departments = create_department_csv(args.source + '/' + args.departments) print(departments) + if not os.path.exists(args.source + '/' + args.towns): + logger.critical('can\'t find source file for departments') + towns = create_towns_csv(args.source + '/' + args.towns) + print(towns) + sys.exit()