Skip to content

Commit

Permalink
More proxies sources
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Pitkov committed Feb 26, 2023
1 parent 5bb8b4d commit ee9c768
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 27 deletions.
69 changes: 47 additions & 22 deletions account_generator_helper/proxies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@ def _proxy_list(self, _):
proxies = r.text.split()
self.__logger.debug(
'{} parsed {} {} proxy'.format(url.split('/api/')[0].split('/v')[0], len(proxies), proxy_type.name))
result_proxies = set()
for row in proxies:
result_proxies.add(Proxy(proxy_type, *row.split(':'), None))
result_proxies = {Proxy(proxy_type, *row.split(':'), None) for row in proxies}

with self.__lock:
self.__proxies.union(result_proxies)
self.__proxies = self.__proxies.union(result_proxies)

def _ssl_proxies(self, _):
for proxy_type, url in zip([ProxyType.HTTP, ProxyType.HTTPS, ProxyType.SOCKS4],
Expand All @@ -62,10 +61,9 @@ def _ssl_proxies(self, _):
country = Counties(country.upper())
except ValueError:
country = None

result_proxies.add(Proxy(proxy_type, address, port, country))
with self.__lock:
self.__proxies.union(result_proxies)
self.__proxies = self.__proxies.union(result_proxies)

def _geo_node(self, _):
try:
Expand All @@ -78,15 +76,15 @@ def _geo_node(self, _):
return
data = r.json().get('data', [])
self.__logger.debug('https://geonode.com parsed {} proxy'.format(len(data)))
result_proxies = set()
for row in data:
try:
country = Counties(row['country'])
except ValueError:
country = None

with self.__lock:
self.__proxies.add(Proxy(ProxyType(row['protocols'][0] if row['protocols'][0] != 'https' else 'http'),
row['ip'], row['port'], country))
result_proxies.add(Proxy(ProxyType(row['protocols'][0] if row['protocols'][0] != 'https' else 'http'), row['ip'], row['port'], country))
with self.__lock:
self.__proxies = self.__proxies.union(result_proxies)

def _advanced(self, max_page):
i = 1
Expand All @@ -104,20 +102,20 @@ def _advanced(self, max_page):
if not table:
continue
proxies_rows = table.find_all('tr')
result_proxies = set()
for row in proxies_rows:
_, address, port, proxy_type, country, _, _ = row.find_all('td')
try:
country = Counties(country.find('a').text)
except (AttributeError, ValueError):
country = None

with self.__lock:
try:
self.__proxies.add(Proxy(getattr(ProxyType, proxy_type.find('a').text.upper()),
base64.b64decode(address['data-ip']).decode(),
base64.b64decode(port['data-port']).decode(), country))
except AttributeError:
pass
try:
result_proxies.add(Proxy(getattr(ProxyType, proxy_type.find('a').text.upper()),
base64.b64decode(address['data-ip']).decode(), base64.b64decode(port['data-port']).decode(), country))
except AttributeError:
pass
with self.__lock:
self.__proxies = self.__proxies.union(result_proxies)
self.__logger.debug('https://advanced.name page {} parsed {} proxy'.format(i + 1, len(proxies_rows)))
if page.find('ul', {'class': 'pagination pagination-lg'}).find_all('a')[-2].text == str(i):
break
Expand Down Expand Up @@ -150,10 +148,37 @@ def _open_proxy(self, _):
country = Counties(main_data['code'])
except (AttributeError, ValueError):
country = None
result_proxies = {Proxy(proxy_type, *item.split(':'), country) for item in main_data.get('items', [])}

for item in main_data.get('items', []):
with self.__lock:
self.__proxies.add(Proxy(proxy_type, *item.split(':'), country))
with self.__lock:
self.__proxies = self.__proxies.union(result_proxies)

def _get_github(self, _):
urls = [
('https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/socks5.txt', ProxyType.SOCKS5),
('https://raw.githubusercontent.com/hookzof/socks5_list/master/proxy.txt', ProxyType.SOCKS5),
('https://raw.githubusercontent.com/prxchk/proxy-list/main/socks5.txt', ProxyType.SOCKS5),

This comment has been minimized.

Copy link
@prxchk

prxchk Mar 7, 2023

👍

('https://raw.githubusercontent.com/HyperBeats/proxy-list/main/socks5.txt', ProxyType.SOCKS5),
('https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/socks4.txt', ProxyType.SOCKS4),
('https://raw.githubusercontent.com/prxchk/proxy-list/main/socks4.txt', ProxyType.SOCKS4),
('https://raw.githubusercontent.com/HyperBeats/proxy-list/main/socks4.txt', ProxyType.SOCKS4),
('https://raw.githubusercontent.com/TheSpeedX/SOCKS-List/master/http.txt', ProxyType.HTTP),
('https://raw.githubusercontent.com/prxchk/proxy-list/main/http.txt', ProxyType.HTTP),
('https://raw.githubusercontent.com/HyperBeats/proxy-list/main/http.txt', ProxyType.HTTP),
('https://raw.githubusercontent.com/HyperBeats/proxy-list/main/https.txt', ProxyType.HTTPS)
]
for url, proxy_type in urls:
try:
r = requests.get(url, timeout=10)
except requests.exceptions.ReadTimeout:
return
if not r.ok:
continue
proxies = r.text.split('\n')
self.__logger.debug('{} parsed {} {} proxy'.format(url, len(proxies), proxy_type.name))
result_proxies = {Proxy(proxy_type, *item.strip().split(':'), None) for item in proxies if item.strip()}
with self.__lock:
self.__proxies = self.__proxies.union(result_proxies)

@staticmethod
def _re_proxy(string):
Expand Down Expand Up @@ -186,7 +211,7 @@ def parse_proxies(self, max_page=0):
:param max_page: Maximum number of pages from which you need to parse the proxy, 0 if you need to parse all.
"""
self.__logger.debug('Start parsing proxy')
parsers = [self._proxy_list, self._ssl_proxies, self._geo_node, self._advanced, self._open_proxy]
parsers = [self._proxy_list, self._ssl_proxies, self._geo_node, self._advanced, self._open_proxy, self._get_github]
threads = [Thread(target=parser, args=(max_page,), daemon=True) for parser in parsers]
[thread.start() for thread in threads]
[thread.join() for thread in threads]
Expand Down
8 changes: 8 additions & 0 deletions account_generator_helper/temp_phone/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ class ProblemWithFetchMessages(Exception):

class ProblemWithCounties(Exception):
"""Problem with fetch counties"""


class NoNumbers(Exception):
"""Not found numbers"""


class NoCountyFound(Exception):
"""No specific country found"""
7 changes: 6 additions & 1 deletion account_generator_helper/temp_phone/receive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from account_generator_helper.countries import Counties
from typing import List

from ..exceptions import NoCountyFound

headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36'
Expand Down Expand Up @@ -33,7 +34,11 @@ def get_country(self, country: Counties) -> Country:
"""
if not self._countries:
self.get_counties()
return self._countries.get(country, None)
result = self._countries.get(country, None)
if not result:
raise NoCountyFound()

return result

def get_random_country(self) -> Country:
"""
Expand Down
8 changes: 7 additions & 1 deletion account_generator_helper/temp_phone/receive/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from account_generator_helper.countries import Counties
from typing import List

from ..exceptions import NoNumbers


class Country:
def __init__(self, s, country, url):
Expand All @@ -28,7 +30,11 @@ def get_number(self) -> Phone:
"""
:return: Random number.
"""
return random.choice(self.get_numbers())
numbers = self.get_numbers()
if not numbers:
raise NoNumbers()

return random.choice(numbers)

def __repr__(self):
return '(Country country={})'.format(self._country.name)
3 changes: 2 additions & 1 deletion account_generator_helper/temp_phone/receive_sms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import re

from ..exceptions import ProblemWithCounties
from ..receive import Receive
from bs4 import BeautifulSoup
from ..exceptions import ProblemWithFetchNumbers
from .country import Country
from ...countries import Counties

Expand Down
2 changes: 1 addition & 1 deletion account_generator_helper/temp_phone/receive_sms/phone.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ..receive import phone
from ..exceptions import ProblemWithFetchNumbers
from ..exceptions import ProblemWithFetchMessages
from ..message import Message
from bs4 import BeautifulSoup

Expand Down
1 change: 1 addition & 0 deletions examples/proxies/proxies.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from account_generator_helper import Proxies


proxies = Proxies()

proxies.parse_proxies()
Expand Down
2 changes: 1 addition & 1 deletion examples/temp_phone/receive_sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

phone = ReceiveSms()

country = phone.get_country(Counties.UKRAINE)
country = phone.get_country(Counties.POLAND)
phone = country.get_number()
print('Phone number :', phone.number) # Phone number : 380665327743

Expand Down

0 comments on commit ee9c768

Please sign in to comment.