X-Git-Url: https://code.communitydata.science/covid19.git/blobdiff_plain/04e00f363bec0c5aa349e6c85f9a78d6ee70c3fd..d655e1ce9332f039a2bd271776752b3f74863848:/wikipedia/scripts/fetch_enwiki_revisions.py diff --git a/wikipedia/scripts/fetch_enwiki_revisions.py b/wikipedia/scripts/fetch_enwiki_revisions.py index e8f177d..6a3563f 100755 --- a/wikipedia/scripts/fetch_enwiki_revisions.py +++ b/wikipedia/scripts/fetch_enwiki_revisions.py @@ -80,10 +80,11 @@ def main(): 'sha1' : 'sha1', 'contentmodel' : 'contentmodel', 'tags' : 'tags', + 'flags' : 'flags', 'comment' : 'comment', 'content' : 'content' } - exclude_from_tsv = ['tags', 'comment', 'content'] + exclude_from_tsv = ['tags', 'comment', 'content', 'flags'] # load the list of articles with open(article_filename, 'r') as infile: @@ -101,7 +102,7 @@ def main(): tsv_fields = [e for e in tsv_fields if e not in exclude_from_tsv] # add special export fields - tsv_fields = tsv_fields + ['url', 'export_timestamp', 'export_commit'] + tsv_fields = tsv_fields + ['anon', 'minor', 'url', 'export_timestamp', 'export_commit'] export_info = { 'git_commit' : export_git_hash, 'timestamp' : export_time } @@ -113,7 +114,7 @@ def main(): tsv_writer.writeheader() for article in article_list: - logging.info(f"pulling revisiosn for: {article}") + logging.info(f"pulling revisions for: {article}") for rev in get_revisions_for_page(article): logging.debug(f"processing raw revision: {rev}") @@ -127,6 +128,22 @@ def main(): if "sha1" not in rev: rev["sha1"] = "" + if "userhidden" in rev: + rev["user"] = "" + rev["userid"] = "" + + # recode anon so it's true or false instead of present/missing + if "anon" in rev: + rev["anon"] = True + else: + rev["anon"] = False + + # let's recode "minor" in the same way + if "minor" in rev: + rev["minor"] = True + else: + rev["minor"] = False + # add page title information rev['title'] = rev['page']['title'] rev['pageid'] = rev['page']['pageid'] @@ -141,8 +158,6 @@ def main(): rev['export_commit'] = export_git_short_hash tsv_writer.writerow({k: rev[k] for k in tsv_fields}) - break if __name__ == "__main__": - main()