added input caching to aoc
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -159,4 +159,5 @@ cython_debug/ | |||||||
| #  and can be added to the global gitignore or merged into this file.  For a more nuclear | #  and can be added to the global gitignore or merged into this file.  For a more nuclear | ||||||
| #  option (not recommended) you can uncomment the following to ignore the entire idea folder. | #  option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||||||
| .idea/ | .idea/ | ||||||
|  | input/ | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| import os | import os | ||||||
|  | import shutil | ||||||
| import urllib.request | import urllib.request | ||||||
|  |  | ||||||
| from cpl_core.console import Console | from cpl_core.console import Console | ||||||
| @@ -21,6 +22,18 @@ def get_input(year: int, day: int) -> str: | |||||||
|     """ |     """ | ||||||
|     original code from https://github.com/anthonywritescode/aoc2022/blob/main/support/support.py |     original code from https://github.com/anthonywritescode/aoc2022/blob/main/support/support.py | ||||||
|     """ |     """ | ||||||
|     url = f'https://adventofcode.com/{year}/day/{day}/input' |     file = f'input/{year}/input_{day}.txt' | ||||||
|     req = urllib.request.Request(url, headers=_get_cookie_headers()) |     if not os.path.exists(file): | ||||||
|     return urllib.request.urlopen(req).read().decode() |         os.makedirs(os.path.dirname(file)) | ||||||
|  |         url = f'https://adventofcode.com/{year}/day/{day}/input' | ||||||
|  |         req = urllib.request.Request(url, headers=_get_cookie_headers()) | ||||||
|  |         txt = urllib.request.urlopen(req).read().decode() | ||||||
|  |         with open(file, 'w+') as f: | ||||||
|  |             f.write(txt) | ||||||
|  |             f.close() | ||||||
|  |  | ||||||
|  |     txt = '' | ||||||
|  |     with open(file, 'r') as f: | ||||||
|  |         txt = f.read() | ||||||
|  |         f.close() | ||||||
|  |     return txt | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user