]> code.communitydata.science - covid19.git/blobdiff - wikipedia/scripts/wikiproject_scraper.py
revisions to reflect updated example filename and clean comments in R code
[covid19.git] / wikipedia / scripts / wikiproject_scraper.py
index 6e01051dd531b98b1d768dc0db55babe93581f7c..b03b04c4da0a9634bd89e9ac4362787d48461d8e 100755 (executable)
@@ -25,12 +25,13 @@ import logging
 import re
 import math
 from bs4 import BeautifulSoup
+import digobs
 
 def parse_args():
 
     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('-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), 
     args = parser.parse_args()
 
@@ -41,24 +42,11 @@ def main():
     args = parse_args()
     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
     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:
-        logging.basicConfig(level=loglevel)
+        logging.basicConfig(level=args.logging_level)
 
     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()

Community Data Science Collective || Want to submit a patch?