| import os | |
| from concurrent.futures import ThreadPoolExecutor | |
| import requests | |
| OUTPUT_DIR = "urls" | |
| NUM_ROWS = 1800 | |
| MAX_WORKERS = 10 | |
| def main(): | |
| if not os.path.isdir(OUTPUT_DIR): | |
| os.mkdir(OUTPUT_DIR) | |
| for i, grid_size in enumerate(['4x7', '4x6', '4x5', '4x4', '3x5', '3x4']): | |
| for j, difficulty in enumerate(['challenging', 'moderate', 'easy']): | |
| file_path = f'{OUTPUT_DIR}/{difficulty}{grid_size}.txt' | |
| count = 0 | |
| if os.path.exists(file_path): | |
| with open(file_path) as rr: | |
| count = len(rr.readlines()) | |
| print(f"PROCESS: {file_path}, {count=}") | |
| with open(file_path, 'a') as file: | |
| with ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor: | |
| for _ in range(NUM_ROWS - count): | |
| executor.submit(fetch_one, file, i, j) | |
| def fetch_one(file, i, j): | |
| response = requests.post('https://logic.puzzlebaron.com/init2.php', data={'sg': 6 - i, 'sd': 3 - j}) | |
| html_content = response.text | |
| sfx = html_content.partition('<form method="post" action="play.php?u2=')[2].partition('">')[0] | |
| if not sfx.isalnum(): | |
| print("FAIL", sfx) | |
| url = f"https://logic.puzzlebaron.com/play.php?u2={sfx}\n" | |
| file.write(url) | |
| main() | |