diff --git a/rank_progress.py b/rank_progress.py --- a/rank_progress.py +++ b/rank_progress.py @@ -1,7 +1,10 @@ import re +import io from itertools import groupby from datetime import datetime import argparse +import urllib.request +from zipfile import ZipFile class Record: @@ -95,6 +98,7 @@ def main(s, since, to, args): records = filter(lambda rec: rec is not None, records) national_records = filter(lambda rec: rec.country_code == args.country_code, records) player_records = groupby(national_records, lambda rec: rec.pin) + print("Detecting rank changes...") for (pin, recs) in player_records: tourneys = list(recs) @@ -114,8 +118,8 @@ def main(s, since, to, args): steps = [r for r in steps if since <= r.date <= to] if steps: + print() print("\n".join(map(str, steps))) - print() if __name__ == "__main__": @@ -123,13 +127,26 @@ if __name__ == "__main__": parser.add_argument("since", help="a date in YYYYMMDD format") parser.add_argument("to", nargs="?", help="a date in YYYYMMDD format") parser.add_argument("-c", "--country-code", default="CZ", help="a two letter country code, default=CZ") + parser.add_argument("-f", "--file", help="a path to the rating history file") args = parser.parse_args() since = datetime.strptime(args.since, "%Y%m%d") to = datetime.strptime(args.to, "%Y%m%d") if args.to else datetime.now() - with open("/tmp/all.hst") as f: - s = f.read() + if args.file: + print("Reading {} ...".format(args.file)) + with ZipFile(args.file) as f: + s = f.read("all.hst").decode("utf-8") + else: + url = "https://europeangodatabase.eu/EGD/EGD_2_0/downloads/hisgor.zip" + print("Downloading data from {} ...".format(url)) + with urllib.request.urlopen(url) as f: + compressed_data = f.read() + with ZipFile(io.BytesIO(compressed_data)) as g: + s = g.read("all.hst").decode("utf-8") - main(s, since, to, args) \ No newline at end of file + print("Processing...") + main(s, since, to, args) + + print("\nDone.") \ No newline at end of file