From b5b58b0a3dac09591f7fce72f2515b238c309048 Mon Sep 17 00:00:00 2001 From: Themi Date: Sat, 21 Aug 2021 07:19:15 -0500 Subject: [PATCH] -Created __init__.py -Plugins that crash now have fails reported and logged as info -Added plugin geonode.py -Removed proxy test method --- src/FreeProxyScraper.py | 5 +++-- src/__init__.py | 0 src/plugins/geonode.py | 36 ++++++++++++++++++++++++++++++++++++ src/utils.py | 5 ----- 4 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 src/__init__.py create mode 100644 src/plugins/geonode.py diff --git a/src/FreeProxyScraper.py b/src/FreeProxyScraper.py index c5c822b..538992e 100644 --- a/src/FreeProxyScraper.py +++ b/src/FreeProxyScraper.py @@ -1,4 +1,4 @@ -import traceback +import logging from src.utils import Plugins, GenLimiter, Proxy from typing import Iterator @@ -20,7 +20,8 @@ def exec_iter_plugin(self, method_name: str, sort_asc_fails: bool = True, *args, for value in return_iter: yield value except Exception: - traceback.print_exc() + logging.info(f"FreeProxyScraper plugin \"{plugin.plugin_name}\" has crashed") + plugin.report_fail() continue def find_proxies(self, limit: int = -1) -> Iterator[Proxy]: diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/plugins/geonode.py b/src/plugins/geonode.py new file mode 100644 index 0000000..5dc0a11 --- /dev/null +++ b/src/plugins/geonode.py @@ -0,0 +1,36 @@ +import requests +from src.utils import Proxy, Plugin +from typing import Iterator + + +anon_dict = {"transparent": 0, "anonymous": 1, "elite": 2} + + +class GeoNode(Plugin): + plugin_name = "Geonode" + plugin_url = "https://geonode.com/free-proxy-list" + + def find(self) -> Iterator[Proxy]: + page = 1 + while True: + resource = f"https://proxylist.geonode.com/api/proxy-list?limit=15&page={page}&sort_by=lastChecked&sort_type=desc" + response = requests.get(resource) + + if response.status_code != 200: + self.report_fail() + return + + response_json = response.json() + + if len(response_json["data"]) == 0: + return + + for proxy_json in response_json["data"]: + yield Proxy( + ip=proxy_json["ip"], + anon_level=anon_dict[proxy_json["anonymityLevel"]], + port=int(proxy_json["port"]), + protocol=proxy_json["protocols"][0] + ) + + page += 1 diff --git a/src/utils.py b/src/utils.py index 3bfd5c4..1f20509 100644 --- a/src/utils.py +++ b/src/utils.py @@ -89,11 +89,6 @@ def address(self) -> str: """Gets the full form address for the proxy used for connecting""" return f"{self.protocol}://{self.ip}:{self.port}" - def test(self) -> bool: - """Tests the proxy to see if it's operational""" - # todo implement proxy test method - return True - class Plugin(ABC): """Represents a plugin"""