import aiohttp import asyncio import json import time # --- CONFIGURATION --- START_ID = 3 END_ID = 3268 OUTPUT_FILE = "found_books.txt" # Limit concurrent connections to avoid crashing Termux or getting IP banned # 50 is a safe speed that is still very fast. CONCURRENT_REQUESTS = 50 url_template = "https://flipbook.apps.gwo.pl/book/getEbookInfo/bookId:{}" async def fetch_book(session, book_id, semaphore): async with semaphore: target_url = url_template.format(book_id) try: async with session.get(target_url, timeout=10) as response: if response.status != 200: return None # Read response text text = await response.text() # Try to parse JSON. # If the response is the HTML error message, this will fail. try: data = json.loads(text) except json.JSONDecodeError: return None # It was likely the "Przepraszamy" HTML text # --- FILTERING LOGIC --- # 1. demo must be "0" # 2. pages must be >= 100 # Note: The API returns strings, so we cast to int for comparison if data.get("demo") == "0" and int(data.get("pages", 0)) >= 100: return f"ID: {data['id']} | Title: {data['title']}" return None except Exception as e: # Ignore connection errors to keep the script moving return None async def main(): print(f"Starting scan from {START_ID} to {END_ID}...") start_time = time.time() semaphore = asyncio.Semaphore(CONCURRENT_REQUESTS) tasks = [] results = [] async with aiohttp.ClientSession() as session: # Create a list of tasks for all IDs for i in range(START_ID, END_ID + 1): task = asyncio.create_task(fetch_book(session, i, semaphore)) tasks.append(task) # Wait for all tasks to complete and gather results # We use a simple counter to show progress total = len(tasks) completed = 0 for future in asyncio.as_completed(tasks): res = await future completed += 1 if res: results.append(res) print(f"[FOUND] {res}") # Simple progress indicator every 100 requests if completed % 100 == 0: print(f"Progress: {completed}/{total} checked...") # Write results to file if results: with open(OUTPUT_FILE, "w", encoding="utf-8") as f: for line in results: f.write(line + "\n") print(f"\nSuccess! Saved {len(results)} books to {OUTPUT_FILE}") else: print("\nScan finished. No matching books found.") duration = time.time() - start_time print(f"Total time taken: {duration:.2f} seconds") if __name__ == "__main__": asyncio.run(main())