Changeset - 0e7c4e24c743
[Not reviewed]
default
0 1 0
Laman - 3 years ago 2021-10-20 14:50:48

downloading and decompressing the source file
1 file changed with 21 insertions and 4 deletions:
0 comments (0 inline, 0 general)
rank_progress.py
Show inline comments
 
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
0 comments (0 inline, 0 general)