<commit_before>#!/usr/bin/env python3
import urllib.request
import sys
import zipfile
import os.path

#
# Fetches sample input and output data from kattis.
#

_URL_ = "https://kth.kattis.com/download/sampledata?id="
_USAGE_ = """
fetch.py <problem id>

Fetches input and output data provided by kattis
"""

# Get zipfile and unzip.
def fetch(problem):
	def _reporthook(dataz, datao, data):
		pass
	
	try:
		response = urllib.request.urlretrieve(_URL_+problem, reporthook=_reporthook)
		filename = response[0]
		
		with zipfile.ZipFile(filename) as _zip:
			print("Data downloaded. Unzipping...")
			files_which_already_exist = []
			for n in _zip.namelist():
				if os.path.exists(n):
					files_which_already_exist.append(n)
			if len(files_which_already_exist) > 0:
				print("The following files already exist in your directory and will be replaced:")
				print(" ".join(files_which_already_exist))				
				print()
				ans = input("Continue? (Y/N) ")
				if not ("y" in ans or "Y" in ans):
					sys.exit(1)
			_zip.extractall()
		print("Extracted: " + " ".join(_zip.namelist()))
	except zipfile.BadZipfile as e:
		print("No such problem id: " + problem)
	except Exception as e:
		print(e)
	

def main():
	if len(sys.argv) == 1:
		print(_USAGE_)
		sys.exit(1)
		
	fetch(sys.argv[1])
		
	
	
if __name__ == "__main__":
	main()<commit_msg>Now with option for path to extract to.<commit_after>#!/usr/bin/env python3
import urllib.request
import sys
import zipfile
import os.path
import optparse

#
# Fetches sample input and output data from kattis.
#

_URL_ = "https://kth.kattis.com/download/sampledata?id="
_USAGE_ = """
fetch.py <problem id> [-p <path>]

Fetches input and output data provided by kattis
"""

# Get zipfile and unzip.
def fetch(problem, path=""):
	def _reporthook(dataz, datao, data):
		pass
	
	try:
		response = urllib.request.urlretrieve(_URL_+problem, reporthook=_reporthook)
		filename = response[0]
		
		with zipfile.ZipFile(filename) as _zip:
			print("Data downloaded. Unzipping...")
			files_which_already_exist = []
			for n in _zip.namelist():
				if os.path.exists(n):
					files_which_already_exist.append(n)
			if len(files_which_already_exist) > 0:
				print("The following files already exist in your directory and will be replaced:")
				print(" ".join(files_which_already_exist))				
				print()
				ans = input("Continue? (Y/N) ")
				if not ("y" in ans or "Y" in ans):
					sys.exit(1)
			_zip.extractall(path)
		print("Extracted: " + " ".join(_zip.namelist()))
	except zipfile.BadZipfile as e:
		print("No such problem id: " + problem)
	

def main():
	opt = optparse.OptionParser()
	opt.add_option('-p', '--path', dest='path', metavar='PATH', help='Path where to save the example data.')

	opts, args = opt.parse_args()
	
	if len(args) == 0:
		print(_USAGE_)
		sys.exit(1)
		
	fetch(args[0], opts.path)
		
	
	
if __name__ == "__main__":
	main()
{'fraction_non_alphanumeric': 0.13601665510062458, 'fraction_numerical': 0.004857737682165163, 'mean_word_length': 3.821070234113712, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7495420', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1022, 'n_words': 271}