Skip to content

Commit

Permalink
check_bormes: valores por defecto para -f y -t
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloCastellano committed Jun 7, 2016
1 parent 0571647 commit 8ded52b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions scripts/check_bormes.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def check_range(begin, end, provincia, seccion, directory, download_xml=False):

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Check BORME files are present and not corrupt.')
parser.add_argument('-f', '--fromdate', help='ISO formatted date (ex. 2015-01-01). Default: init')
parser.add_argument('-t', '--to', help='ISO formatted date (ex. 2016-01-01). Default: today')
parser.add_argument('-f', '--fromdate', default='init', help='ISO formatted date (ex. 2015-01-01). Default: init')
parser.add_argument('-t', '--to', default='today', help='ISO formatted date (ex. 2016-01-01). Default: today')
parser.add_argument('-d', '--directory', default=DEFAULT_BORME_ROOT, help='Directory to download files (default is {})'.format(DEFAULT_BORME_ROOT))
parser.add_argument('-s', '--seccion', default=bormeparser.SECCION.A, choices=['A', 'B', 'C'], help='BORME seccion')
parser.add_argument('-p', '--provincia', choices=bormeparser.provincia.ALL_PROVINCIAS, help='BORME provincia')
Expand All @@ -105,15 +105,17 @@ def check_range(begin, end, provincia, seccion, directory, download_xml=False):
bormeparser.download.logger.setLevel(logging.INFO)
logger.setLevel(logging.INFO)

if args.fromdate:
date_from = datetime.datetime.strptime(args.fromdate, '%Y-%m-%d').date()
else:
if args.fromdate == 'init':
date_from = FIRST_BORME[2009]

if args.to:
date_to = datetime.datetime.strptime(args.to, '%Y-%m-%d').date()
elif args.fromdate == 'today':
date_from = datetime.date.today()
else:
date_from = datetime.datetime.strptime(args.fromdate, '%Y-%m-%d').date()

if args.to == 'today':
date_to = datetime.date.today()
else:
date_to = datetime.datetime.strptime(args.to, '%Y-%m-%d').date()

try:
check_range(date_from, date_to, args.provincia, args.seccion, args.directory, args.download_xml)
Expand Down

0 comments on commit 8ded52b

Please sign in to comment.