Write to timestamped file
This commit is contained in:
parent
2fa30b1d13
commit
1af8a63717
16
main.py
16
main.py
@ -1,6 +1,7 @@
|
|||||||
"""Harvester: Proxy collection tool
|
"""Harvester: Proxy collection tool
|
||||||
Inspired by https://github.com/acidvegas/proxytools
|
Inspired by https://github.com/acidvegas/proxytools
|
||||||
"""
|
"""
|
||||||
|
import time
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import logging
|
import logging
|
||||||
from harvester.proxy import fetch_all, validate_socks
|
from harvester.proxy import fetch_all, validate_socks
|
||||||
@ -13,6 +14,11 @@ def load_urls(path):
|
|||||||
return urls
|
return urls
|
||||||
|
|
||||||
|
|
||||||
|
def write_file(path, data):
|
||||||
|
with open(path, 'w', encoding='utf-8') as file:
|
||||||
|
file.write(data)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main entry point."""
|
"""Main entry point."""
|
||||||
logging.basicConfig(level=logging.WARN)
|
logging.basicConfig(level=logging.WARN)
|
||||||
@ -33,7 +39,7 @@ def main():
|
|||||||
response = future.result()
|
response = future.result()
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except Exception as exception:
|
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))
|
logging.info(str(exception))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -41,9 +47,11 @@ def main():
|
|||||||
valid.append(proxy)
|
valid.append(proxy)
|
||||||
print(f'{proxy} -> {ip}')
|
print(f'{proxy} -> {ip}')
|
||||||
|
|
||||||
with open('data/valid-socks.txt', 'w', encoding='utf-8') as file:
|
# Write to file with timestamp
|
||||||
file.write('\n'.join(valid))
|
write_file(
|
||||||
|
path=f'proxies/valid-socks-{time.strftime("%Y%m%d%H%M%S")}.txt',
|
||||||
|
data='\n'.join(valid)
|
||||||
|
)
|
||||||
for proxy in valid:
|
for proxy in valid:
|
||||||
print(proxy)
|
print(proxy)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user