forked from clementruin/CityDashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
57 lines (46 loc) · 1.43 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import argparse
import sys
import json
import numpy as np
import indicator
import benchmark
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--function', help='Input function', required=True)
parser.add_argument('-a', '--argument', help='Output argument', required=False)
args = parser.parse_args()
def main():
"""Retrieves and assert user's input
"""
function = args.function
if len(sys.argv) >= 4:
argument = args.argument
else:
argument = "None"
assert function in ['benchmark', 'indicator'], \
'Function is not one of benchmark or indicator : ' + function
process(function, argument)
def get_code(arg):
"""Determines the insee code of the user's input arguement
"""
try:
if int(arg) >= 1000 and int(arg) < 99000:
return arg
#solution temporaire, on pourra utiliser un autre dico pour matcher les noms et code
except BaseException:
reader = open('static_dic/activite2014.json', 'r')
dico = json.load(reader)
for key in dico:
if dico[key]["nom"]==arg:
return key
class InputError(Exception):
pass
def process(function, argument):
code = get_code(argument)
if code == None:
raise InputError
if function == 'indicator':
print(indicator.main(code))
elif function == 'benchmark':
print(benchmark.main(code))
if __name__ == '__main__':
main()