use the type= feature in argparse
- integrated the type= feature in argparse in all three scripts - removed some redundant code from the third file
This commit is contained in:
parent
17c3f75389
commit
b457cd726b
@ -26,7 +26,7 @@ def parse_args():
|
|||||||
parser.add_argument('-o', '--output_folder', help='Where to save output', default="wikipedia/data", type=str)
|
parser.add_argument('-o', '--output_folder', help='Where to save output', default="wikipedia/data", type=str)
|
||||||
parser.add_argument('-i', '--article_file', help='File listing article names', default="wikipedia/resources/enwp_wikiproject_covid19_articles.txt", type=str)
|
parser.add_argument('-i', '--article_file', help='File listing article names', default="wikipedia/resources/enwp_wikiproject_covid19_articles.txt", type=str)
|
||||||
parser.add_argument('-d', '--query_date', help='Date if not yesterday, in YYYYMMDD format.', type=str)
|
parser.add_argument('-d', '--query_date', help='Date if not yesterday, in YYYYMMDD format.', type=str)
|
||||||
parser.add_argument('-L', '--logging_level', help='Logging level. Options are debug, info, warning, error, critical. Default: info.', default='info', type=str),
|
parser.add_argument('-L', '--logging_level', help='Logging level. Options are debug, info, warning, error, critical. Default: info.', default='info', type=digobs.get_loglevel),
|
||||||
parser.add_argument('-W', '--logging_destination', help='Logging destination file. (default: standard error)', type=str),
|
parser.add_argument('-W', '--logging_destination', help='Logging destination file. (default: standard error)', type=str),
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
return(args)
|
return(args)
|
||||||
@ -45,14 +45,11 @@ def main():
|
|||||||
yesterday = datetime.datetime.today() - datetime.timedelta(days=1)
|
yesterday = datetime.datetime.today() - datetime.timedelta(days=1)
|
||||||
query_date = yesterday.strftime("%Y%m%d")
|
query_date = yesterday.strftime("%Y%m%d")
|
||||||
|
|
||||||
#handle -L
|
|
||||||
loglevel = digobs.get_loglevel(args.logging_level)
|
|
||||||
|
|
||||||
#handle -W
|
#handle -W
|
||||||
if args.logging_destination:
|
if args.logging_destination:
|
||||||
logging.basicConfig(filename=args.logging_destination, filemode='a', level=loglevel)
|
logging.basicConfig(filename=args.logging_destination, filemode='a', level=args.logging_level)
|
||||||
else:
|
else:
|
||||||
logging.basicConfig(level=loglevel)
|
logging.basicConfig(level=args.logging_level)
|
||||||
|
|
||||||
export_time = str(datetime.datetime.now())
|
export_time = str(datetime.datetime.now())
|
||||||
export_date = datetime.datetime.today().strftime("%Y%m%d")
|
export_date = datetime.datetime.today().strftime("%Y%m%d")
|
||||||
|
@ -26,7 +26,7 @@ def parse_args():
|
|||||||
parser = argparse.ArgumentParser(description='Call the views API to collect Wikipedia revision data.')
|
parser = argparse.ArgumentParser(description='Call the views API to collect Wikipedia revision data.')
|
||||||
parser.add_argument('-o', '--output_folder', help='Where to save output', default="wikipedia/data", type=str)
|
parser.add_argument('-o', '--output_folder', help='Where to save output', default="wikipedia/data", type=str)
|
||||||
parser.add_argument('-i', '--article_file', help='File listing article names', default="wikipedia/resources/enwp_wikiproject_covid19_articles.txt", type=str)
|
parser.add_argument('-i', '--article_file', help='File listing article names', default="wikipedia/resources/enwp_wikiproject_covid19_articles.txt", type=str)
|
||||||
parser.add_argument('-L', '--logging_level', help='Logging level. Options are debug, info, warning, error, critical. Default: info.', default='info', type=str),
|
parser.add_argument('-L', '--logging_level', help='Logging level. Options are debug, info, warning, error, critical. Default: info.', default='info', type=digobs.get_loglevel),
|
||||||
parser.add_argument('-W', '--logging_destination', help='Logging destination file. (default: standard error)', type=str),
|
parser.add_argument('-W', '--logging_destination', help='Logging destination file. (default: standard error)', type=str),
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
return(args)
|
return(args)
|
||||||
@ -37,14 +37,11 @@ def main():
|
|||||||
output_path = args.output_folder
|
output_path = args.output_folder
|
||||||
article_filename = args.article_file
|
article_filename = args.article_file
|
||||||
|
|
||||||
#handle -L
|
|
||||||
loglevel = digobs.get_loglevel(args.logging_level)
|
|
||||||
|
|
||||||
#handle -W
|
#handle -W
|
||||||
if args.logging_destination:
|
if args.logging_destination:
|
||||||
logging.basicConfig(filename=args.logging_destination, filemode='a', level=loglevel)
|
logging.basicConfig(filename=args.logging_destination, filemode='a', level=args.logging_level)
|
||||||
else:
|
else:
|
||||||
logging.basicConfig(level=loglevel)
|
logging.basicConfig(level=args.logging_level)
|
||||||
|
|
||||||
export_time = str(datetime.datetime.now())
|
export_time = str(datetime.datetime.now())
|
||||||
export_date = datetime.datetime.today().strftime("%Y%m%d")
|
export_date = datetime.datetime.today().strftime("%Y%m%d")
|
||||||
|
@ -30,7 +30,7 @@ def parse_args():
|
|||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Get a list of pages tracked by the COVID-19 Wikiproject.')
|
parser = argparse.ArgumentParser(description='Get a list of pages tracked by the COVID-19 Wikiproject.')
|
||||||
parser.add_argument('-o', '--output_file', help='Where to save output', default="wikipedia/resources/enwp_wikiproject_covid19_articles.txt", type=str)
|
parser.add_argument('-o', '--output_file', help='Where to save output', default="wikipedia/resources/enwp_wikiproject_covid19_articles.txt", type=str)
|
||||||
parser.add_argument('-L', '--logging_level', help='Logging level. Options are debug, info, warning, error, critical. Default: info.', default='info'),
|
parser.add_argument('-L', '--logging_level', help='Logging level. Options are debug, info, warning, error, critical. Default: info.', default='info', type=digobs.get_loglevel),
|
||||||
parser.add_argument('-W', '--logging_destination', help='Logging destination file. (default: standard error)', type=str),
|
parser.add_argument('-W', '--logging_destination', help='Logging destination file. (default: standard error)', type=str),
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -41,24 +41,11 @@ def main():
|
|||||||
args = parse_args()
|
args = parse_args()
|
||||||
outputFile = args.output_file
|
outputFile = args.output_file
|
||||||
|
|
||||||
#handle -L
|
|
||||||
loglevel_mapping = { 'debug' : logging.DEBUG,
|
|
||||||
'info' : logging.INFO,
|
|
||||||
'warning' : logging.WARNING,
|
|
||||||
'error' : logging.ERROR,
|
|
||||||
'critical' : logging.CRITICAL }
|
|
||||||
|
|
||||||
if args.logging_level in loglevel_mapping:
|
|
||||||
loglevel = loglevel_mapping[args.logging_level]
|
|
||||||
else:
|
|
||||||
print("Choose a valid log level: debug, info, warning, error, or critical")
|
|
||||||
exit
|
|
||||||
|
|
||||||
#handle -W
|
#handle -W
|
||||||
if args.logging_destination:
|
if args.logging_destination:
|
||||||
logging.basicConfig(filename=args.logging_destination, filemode='a', level=loglevel)
|
logging.basicConfig(filename=args.logging_destination, filemode='a', level=args.logging_level)
|
||||||
else:
|
else:
|
||||||
logging.basicConfig(level=loglevel)
|
logging.basicConfig(level=args.logging_level)
|
||||||
|
|
||||||
export_git_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode().strip()
|
export_git_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode().strip()
|
||||||
export_git_short_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode().strip()
|
export_git_short_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).decode().strip()
|
||||||
|
Loading…
Reference in New Issue
Block a user