swiftshadow 1.1.0__py3-none-any.whl → 1.2.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
swiftshadow/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- from swiftshadow.providers import Proxyscrape, Scrapingant
1
+ from swiftshadow.providers import Providers
2
2
 
3
3
 
4
4
  def QuickProxy(countries: list = [], protocol: str = "http"):
@@ -13,7 +13,13 @@ def QuickProxy(countries: list = [], protocol: str = "http"):
13
13
  Returns:
14
14
  proxyObject (dict): A working proxy object.
15
15
  """
16
- try:
17
- return Proxyscrape(1, countries=countries, protocol=protocol)[0]
18
- except:
19
- return Scrapingant(1, countries=countries, protocol=protocol)[0]
16
+ for providerDict in Providers:
17
+ if protocol not in providerDict["protocols"]:
18
+ continue
19
+ if (len(countries) != 0) and (not providerDict["countryFilter"]):
20
+ continue
21
+ try:
22
+ return providerDict["provider"](1, countries, protocol)[0]
23
+ except:
24
+ continue
25
+ return None
swiftshadow/classes.py CHANGED
@@ -1,7 +1,8 @@
1
1
  from requests import get
2
2
  from random import choice
3
3
  from json import dump, load
4
- from swiftshadow.providers import Proxyscrape, Scrapingant, Providers
4
+ from swiftshadow.helpers import log
5
+ from swiftshadow.providers import Providers
5
6
  import swiftshadow.cache as cache
6
7
  import logging
7
8
  import sys
@@ -74,20 +75,6 @@ class Proxy:
74
75
  logger.addHandler(fileHandler)
75
76
  self.update()
76
77
 
77
- def checkIp(self, ip, cc, protocol):
78
- if (ip[1] == cc or cc == None) and ip[2] == protocol:
79
- proxy = {ip[2]: ip[0]}
80
- try:
81
- oip = get(f"{protocol}://ipinfo.io/ip", proxies=proxy).text
82
- except:
83
- return False
84
- if oip.count(".") == 3 and oip != self.mip:
85
- return True
86
- else:
87
- return False
88
- else:
89
- return False
90
-
91
78
  def update(self):
92
79
  try:
93
80
  with open(self.cacheFilePath, "r") as file:
@@ -110,11 +97,16 @@ class Proxy:
110
97
  logger.info("No cache found. Cache will be created after update")
111
98
 
112
99
  self.proxies = []
113
- self.proxies.extend(Proxyscrape(self.maxProxies, self.countries, self.protocol))
114
- if len(self.proxies) != self.maxProxies:
100
+ for providerDict in Providers:
101
+ if self.protocol not in providerDict["protocols"]:
102
+ continue
103
+ if (len(self.countries) != 0) and (not providerDict["countryFilter"]):
104
+ continue
115
105
  self.proxies.extend(
116
- Scrapingant(self.maxProxies, self.countries, self.protocol)
106
+ providerDict["provider"](self.maxProxies, self.countries, self.protocol)
117
107
  )
108
+ if len(self.proxies) >= self.maxProxies:
109
+ break
118
110
  if len(self.proxies) == 0:
119
111
  logger.warning(
120
112
  "No proxies found for current settings. To prevent runtime error updating the proxy list again.",
swiftshadow/helpers.py CHANGED
@@ -1,25 +1,22 @@
1
- from swiftshadow.constants import CountryCodes
2
1
  from requests import get
2
+ from datetime import datetime
3
3
 
4
4
 
5
- def getCountryCode(countryName):
6
- try:
7
- return CountryCodes[countryName]
8
- except KeyError:
9
- for name in list(CountryCodes.keys()):
10
- if countryName in name:
11
- return CountryCodes[name]
12
-
13
-
14
- def checkProxy(proxy, countries):
15
- if countries != []:
16
- if proxy[-1].upper() not in countries:
17
- return False
5
+ def checkProxy(proxy):
18
6
  proxyDict = {proxy[1]: proxy[0]}
19
7
  try:
20
- resp = get(f"{proxy[1]}://ipinfo.io/ip", proxies=proxyDict, timeout=2).text
8
+ resp = get(
9
+ f"{proxy[1]}://checkip.amazonaws.com", proxies=proxyDict, timeout=2
10
+ ).text
21
11
  if resp.count(".") == 3:
22
12
  return True
23
13
  return False
24
14
  except Exception as e:
25
15
  return False
16
+
17
+
18
+ def log(level, message):
19
+ level = level.upper()
20
+ print(
21
+ f'{datetime.now().strftime("%d/%m/%Y %H:%M:%S")} - [swiftshadow] - {level} : {message}'
22
+ )
swiftshadow/providers.py CHANGED
@@ -1,52 +1,57 @@
1
1
  from requests import get
2
- from swiftshadow.helpers import getCountryCode, checkProxy
2
+ from swiftshadow.helpers import checkProxy
3
3
 
4
-
5
- def Scrapingant(max, countries=[], protocol="http"):
6
- result = []
4
+ def Monosans(max, countries=[],protocol="http"):
5
+ raw = get('https://raw.githubusercontent.com/monosans/proxy-list/main/proxies.json').json()
6
+ results = []
7
7
  count = 0
8
- raw = get("https://scrapingant.com/proxies").text
9
- rows = [i.split("<td>") for i in raw.split("<tr>")]
10
-
11
- def clean(text):
12
- return text[: text.find("<")].strip()
13
-
14
- for row in rows[2:]:
8
+ for proxy in raw:
15
9
  if count == max:
16
- return result
17
- zprotocol = clean(row[3]).lower()
18
- if zprotocol != protocol:
10
+ return results
11
+ if proxy['protocol'] == protocol:
12
+ if len(countries) != 0 and proxy['geolocation']['country']['iso_code'] not in countries:
13
+ continue
14
+ proxy = [f'{proxy['host']}:{proxy['port']}',proxy['protocol']]
15
+ if checkProxy(proxy):
16
+ results.append(proxy)
17
+ count += 1
18
+ return results
19
+
20
+ def Thespeedx(max,countries=[],protocol='http'):
21
+ results = []
22
+ count =0
23
+ raw = get('https://raw.githubusercontent.com/TheSpeedX/PROXY-List/master/http.txt').text
24
+ for line in raw.splitlines():
25
+ if count == max:
26
+ break
27
+ proxy = [line,'http']
28
+ if checkProxy(proxy):
29
+ results.append(proxy)
30
+ print(proxy,True)
31
+ count +=1
32
+ else:
19
33
  continue
20
- cleaned = [
21
- clean(row[1]) + ":" + clean(row[2]),
22
- protocol,
23
- getCountryCode(clean(row[4].split(" ", 1)[1])),
24
- ]
25
- if checkProxy(cleaned, countries):
26
- result.append({cleaned[1]: cleaned[0]})
27
- count += 1
28
- return result
29
-
30
-
31
- def Proxyscrape(max, countries=[], protocol="http"):
32
- result = []
34
+ return results
35
+
36
+ def ProxyScrape(max,countries=[],protocol='http'):
37
+ baseUrl = 'https://api.proxyscrape.com/v3/free-proxy-list/get?request=displayproxies&protocol=http&proxy_format=ipport&format=json'
38
+ results = []
33
39
  count = 0
34
- query = "https://api.proxyscrape.com/v2/?timeout=5000&request=displayproxies&protocol=http"
35
- if countries == []:
36
- query += "&country=all"
40
+ if len(countries) == 0:
41
+ apiUrl = baseUrl + '&country=all'
37
42
  else:
38
- query += "&country=" + ",".join(countries)
39
- if protocol == "https":
40
- query += "&ssl=yes"
41
- ips = get(query).text
42
- for ip in ips.split("\n"):
43
+ apiUrl = baseUrl + '&country=' + ','.join([i.upper() for i in countries])
44
+ raw = get(apiUrl).json()
45
+ for ipRaw in raw['proxies']:
43
46
  if count == max:
44
- return result
45
- proxy = [ip.strip(), protocol, "all"]
46
- if checkProxy(proxy, []):
47
- result.append({proxy[1]: proxy[0]})
47
+ break
48
+ proxy = [ipRaw['proxy'],'http']
49
+ if checkProxy(proxy):
50
+ results.append(proxy)
48
51
  count += 1
49
- return result
50
-
52
+ else:
53
+ print(proxy,False)
54
+ continue
55
+ return results
51
56
 
52
- Providers = [Proxyscrape, Scrapingant]
57
+ Providers = [{'provider':Monosans,'countryFilter':True,'protocols':['http']},{'provider':Thespeedx,'countryFilter':False,'protocols':['http']},{'provider':ProxyScrape,'countryFilter':True,'protocols':['http']}]
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: swiftshadow
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: Free IP Proxy rotator for python
5
5
  Home-page: https://github.com/sachin-sankar/swiftshadow
6
6
  Author: Sachin Sankar
7
7
  Author-email: mail.sachinsankar@gmail.com
8
- Classifier: Development Status :: 2 - Pre-Alpha
8
+ Classifier: Development Status :: 5 - Production/Stable
9
9
  Description-Content-Type: text/markdown
10
10
  License-File: LICENSE
11
11
  Requires-Dist: requests
@@ -14,6 +14,9 @@ Requires-Dist: requests
14
14
 
15
15
  ![PyPI - Downloads](https://img.shields.io/pypi/dm/swiftshadow) ![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/sachin-sankar/swiftshadow?include_prereleases&style=flat)
16
16
 
17
+ > [!TIP]
18
+ > I'm refactoring the library for better speed and maintainability. Future updates might have breaking changes, but I'll keep you posted!
19
+
17
20
  ## About
18
21
 
19
22
  Swiftshadow is a powerful Python library designed to simplify the process of rotating IP proxies for web scraping, data mining, and other automated tasks. With its advanced features, Swiftshadow can help you overcome many of the challenges associated with web scraping, including blocked IP addresses and other forms of detection.
@@ -0,0 +1,11 @@
1
+ swiftshadow/__init__.py,sha256=UGscPyIFECuTgLjcMxp9_QNyfxd6b-msRAtubenBAL0,764
2
+ swiftshadow/cache.py,sha256=tNj07m0Ii_r0wLu9NKTYxOyS8uYeC7BbgFdMnuLqK7Y,411
3
+ swiftshadow/classes.py,sha256=YlXuV5QobEwvIMQDt2sjT173Q-EQbGk6bz5nfyn0Cds,5249
4
+ swiftshadow/constants.py,sha256=FRhoYg8WNaLy8RLDD4BsANlXlY2tctBCdy7sCnkaVY0,6303
5
+ swiftshadow/helpers.py,sha256=RGC-Tq9vWqiddu_KEKYWc_URO-ISm3PXuMBqB_cl7XQ,533
6
+ swiftshadow/providers.py,sha256=qUYUxUuSifwuWWs3KxW2al_T5ee9Lr7MRaTddIR9lyw,2060
7
+ swiftshadow-1.2.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
8
+ swiftshadow-1.2.0.dist-info/METADATA,sha256=RRq0DPKJlgD1gboURK0gtCJ_Fq04P08hinNvz988BjY,2793
9
+ swiftshadow-1.2.0.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
10
+ swiftshadow-1.2.0.dist-info/top_level.txt,sha256=GClzVDF5vWSzqHOwgG2ycQAAJXRxd-QOdP1h3YrHOuM,12
11
+ swiftshadow-1.2.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.42.0)
2
+ Generator: setuptools (70.2.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,11 +0,0 @@
1
- swiftshadow/__init__.py,sha256=cybIN6hvkK06k9aeun0YhhuUSZiEcIr6jdOne2WFWlA,604
2
- swiftshadow/cache.py,sha256=tNj07m0Ii_r0wLu9NKTYxOyS8uYeC7BbgFdMnuLqK7Y,411
3
- swiftshadow/classes.py,sha256=V2ry_xqCQtBKgV2tBRxtQET4kLvikxQCVyUmzp8fGGg,5505
4
- swiftshadow/constants.py,sha256=FRhoYg8WNaLy8RLDD4BsANlXlY2tctBCdy7sCnkaVY0,6303
5
- swiftshadow/helpers.py,sha256=HHZmaBU4qZjypn30jQ5TXHqy8xhr46tSmV9qBdZeBpw,691
6
- swiftshadow/providers.py,sha256=GaVKg5J5hH2HSfdGDPuFivcCu6QB5HFjlVFvrrtNdhw,1490
7
- swiftshadow-1.1.0.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
8
- swiftshadow-1.1.0.dist-info/METADATA,sha256=BcaplWtegmLscWt__ciZ2y3dUE5hoWRoB_jJTX-lHlk,2635
9
- swiftshadow-1.1.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
10
- swiftshadow-1.1.0.dist-info/top_level.txt,sha256=GClzVDF5vWSzqHOwgG2ycQAAJXRxd-QOdP1h3YrHOuM,12
11
- swiftshadow-1.1.0.dist-info/RECORD,,