Write to timestamped file

This commit is contained in:
agatha 2023-11-07 20:30:37 -05:00
parent 2fa30b1d13
commit 1af8a63717

16
main.py
View File

@ -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)