diff --git a/get_states_statistics.py b/get_states_statistics.py index 60ca836..2465c21 100755 --- a/get_states_statistics.py +++ b/get_states_statistics.py @@ -33,6 +33,11 @@ def parse_args(): default='.pgconn' ) + parser.add_argument('--year', + help='Specify year needed to display statistics', + choices=['1982', '1990', '1999', '2008', '2013', '2018'], + default=2018 + ) parser.add_argument('--schema-name', help='Database schema name', @@ -101,7 +106,7 @@ if __name__ == '__main__': INNER JOIN %(schema)s.departement d ON c.dep = d.dep WHERE d.reg = %(state)s """, - {'state': s_id, 'schema': AsIs(args.schema_name)} + {'state': s_id, 'schema': AsIs(args.schema_name), 'tear': args.year } ) try: surface = cur.fetchone() @@ -119,10 +124,10 @@ if __name__ == '__main__': INNER JOIN %(schema)s.departement d ON c.dep = d.dep INNER JOIN %(schema)s.statistique s ON c.com = s.com WHERE s.id_indicateur = 1 - AND s.date_debut = 2018 + AND s.date_debut = %(year)s AND d.reg = %(state)s; """, - {'state': s_id, 'schema': AsIs(args.schema_name)} + {'state': s_id, 'schema': AsIs(args.schema_name), 'year': args.year} ) try: inhabitants = cur.fetchone() @@ -142,12 +147,12 @@ if __name__ == '__main__': INNER JOIN %(schema)s.departement d ON c.dep = d.dep INNER JOIN %(schema)s.statistique s ON c.com = s.com WHERE s.id_indicateur = 1 - AND s.date_debut = 2018 + AND s.date_debut = %(year)s AND d.reg = %(state)s ORDER BY s.valeur DESC LIMIT 10; """, - {'state': s_id, 'schema': AsIs(args.schema_name)} + {'state': s_id, 'schema': AsIs(args.schema_name), 'year': args.year} ) try: towns = cur.fetchall()