diff --git a/main.py b/main.py index 2b15b7a..25c35af 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ """Harvester: Proxy collection tool Inspired by https://github.com/acidvegas/proxytools """ +import time import concurrent.futures import logging from harvester.proxy import fetch_all, validate_socks @@ -13,6 +14,11 @@ def load_urls(path): return urls +def write_file(path, data): + with open(path, 'w', encoding='utf-8') as file: + file.write(data) + + def main(): """Main entry point.""" logging.basicConfig(level=logging.WARN) @@ -33,7 +39,7 @@ def main(): response = future.result() response.raise_for_status() except Exception as exception: - # TODO: Handle exceptions differently. See issues. + # TODO: Handle exceptions differently. See https://git.juggalol.com/agatha/harvester/issues/1. logging.info(str(exception)) continue @@ -41,9 +47,11 @@ def main(): valid.append(proxy) print(f'{proxy} -> {ip}') - with open('data/valid-socks.txt', 'w', encoding='utf-8') as file: - file.write('\n'.join(valid)) - + # Write to file with timestamp + write_file( + path=f'proxies/valid-socks-{time.strftime("%Y%m%d%H%M%S")}.txt', + data='\n'.join(valid) + ) for proxy in valid: print(proxy)