swiftshadow 1.1.0__tar.gz → 1.2.1__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: swiftshadow
3
- Version: 1.1.0
3
+ Version: 1.2.1
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.
@@ -2,6 +2,9 @@
2
2
 
3
3
  ![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)
4
4
 
5
+ > [!TIP]
6
+ > I'm refactoring the library for better speed and maintainability. Future updates might have breaking changes, but I'll keep you posted!
7
+
5
8
  ## About
6
9
 
7
10
  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.
@@ -19,10 +19,10 @@ setup(
19
19
  description="Free IP Proxy rotator for python",
20
20
  long_description=long_description,
21
21
  long_description_content_type="text/markdown",
22
- version="1.1.0",
22
+ version="1.2.1",
23
23
  packages=find_packages(where=".", exclude=["tests"]),
24
24
  install_requires=["requests"],
25
25
  classifiers=[
26
- "Development Status :: 2 - Pre-Alpha",
26
+ "Development Status :: 5 - Production/Stable",
27
27
  ],
28
28
  )
@@ -0,0 +1,25 @@
1
+ from swiftshadow.providers import Providers
2
+
3
+
4
+ def QuickProxy(countries: list = [], protocol: str = "http"):
5
+ """
6
+ This function is a faster alternative to `Proxy` class.
7
+ No caching is done.
8
+
9
+ Args:
10
+ countries: ISO 3166-2 Two letter country codes to filter proxies.
11
+ protocol: HTTP/HTTPS protocol to filter proxies.
12
+
13
+ Returns:
14
+ proxyObject (dict): A working proxy object.
15
+ """
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
@@ -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.",
@@ -0,0 +1,22 @@
1
+ from requests import get
2
+ from datetime import datetime
3
+
4
+
5
+ def checkProxy(proxy):
6
+ proxyDict = {proxy[1]: proxy[0]}
7
+ try:
8
+ resp = get(
9
+ f"{proxy[1]}://checkip.amazonaws.com", proxies=proxyDict, timeout=2
10
+ ).text
11
+ if resp.count(".") == 3:
12
+ return True
13
+ return False
14
+ except Exception as e:
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
+ )
@@ -0,0 +1,72 @@
1
+ from requests import get
2
+ from swiftshadow.helpers import checkProxy
3
+
4
+
5
+ def Monosans(max, countries=[], protocol="http"):
6
+ raw = get(
7
+ "https://raw.githubusercontent.com/monosans/proxy-list/main/proxies.json"
8
+ ).json()
9
+ results = []
10
+ count = 0
11
+ for proxy in raw:
12
+ if count == max:
13
+ return results
14
+ if proxy["protocol"] == protocol:
15
+ if (
16
+ len(countries) != 0
17
+ and proxy["geolocation"]["country"]["iso_code"] not in countries
18
+ ):
19
+ continue
20
+ proxy = [f'{proxy["host"]}:{proxy["port"]}', proxy["protocol"]]
21
+ if checkProxy(proxy):
22
+ results.append(proxy)
23
+ count += 1
24
+ return results
25
+
26
+
27
+ def Thespeedx(max, countries=[], protocol="http"):
28
+ results = []
29
+ count = 0
30
+ raw = get(
31
+ "https://raw.githubusercontent.com/TheSpeedX/PROXY-List/master/http.txt"
32
+ ).text
33
+ for line in raw.splitlines():
34
+ if count == max:
35
+ break
36
+ proxy = [line, "http"]
37
+ if checkProxy(proxy):
38
+ results.append(proxy)
39
+ print(proxy, True)
40
+ count += 1
41
+ else:
42
+ continue
43
+ return results
44
+
45
+
46
+ def ProxyScrape(max, countries=[], protocol="http"):
47
+ baseUrl = "https://api.proxyscrape.com/v3/free-proxy-list/get?request=displayproxies&protocol=http&proxy_format=ipport&format=json"
48
+ results = []
49
+ count = 0
50
+ if len(countries) == 0:
51
+ apiUrl = baseUrl + "&country=all"
52
+ else:
53
+ apiUrl = baseUrl + "&country=" + ",".join([i.upper() for i in countries])
54
+ raw = get(apiUrl).json()
55
+ for ipRaw in raw["proxies"]:
56
+ if count == max:
57
+ break
58
+ proxy = [ipRaw["proxy"], "http"]
59
+ if checkProxy(proxy):
60
+ results.append(proxy)
61
+ count += 1
62
+ else:
63
+ print(proxy, False)
64
+ continue
65
+ return results
66
+
67
+
68
+ Providers = [
69
+ {"provider": Monosans, "countryFilter": True, "protocols": ["http"]},
70
+ {"provider": Thespeedx, "countryFilter": False, "protocols": ["http"]},
71
+ {"provider": ProxyScrape, "countryFilter": True, "protocols": ["http"]},
72
+ ]
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: swiftshadow
3
- Version: 1.1.0
3
+ Version: 1.2.1
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.
@@ -1,19 +0,0 @@
1
- from swiftshadow.providers import Proxyscrape, Scrapingant
2
-
3
-
4
- def QuickProxy(countries: list = [], protocol: str = "http"):
5
- """
6
- This function is a faster alternative to `Proxy` class.
7
- No caching is done.
8
-
9
- Args:
10
- countries: ISO 3166-2 Two letter country codes to filter proxies.
11
- protocol: HTTP/HTTPS protocol to filter proxies.
12
-
13
- Returns:
14
- proxyObject (dict): A working proxy object.
15
- """
16
- try:
17
- return Proxyscrape(1, countries=countries, protocol=protocol)[0]
18
- except:
19
- return Scrapingant(1, countries=countries, protocol=protocol)[0]
@@ -1,25 +0,0 @@
1
- from swiftshadow.constants import CountryCodes
2
- from requests import get
3
-
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
18
- proxyDict = {proxy[1]: proxy[0]}
19
- try:
20
- resp = get(f"{proxy[1]}://ipinfo.io/ip", proxies=proxyDict, timeout=2).text
21
- if resp.count(".") == 3:
22
- return True
23
- return False
24
- except Exception as e:
25
- return False
@@ -1,52 +0,0 @@
1
- from requests import get
2
- from swiftshadow.helpers import getCountryCode, checkProxy
3
-
4
-
5
- def Scrapingant(max, countries=[], protocol="http"):
6
- result = []
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:]:
15
- if count == max:
16
- return result
17
- zprotocol = clean(row[3]).lower()
18
- if zprotocol != protocol:
19
- 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 = []
33
- count = 0
34
- query = "https://api.proxyscrape.com/v2/?timeout=5000&request=displayproxies&protocol=http"
35
- if countries == []:
36
- query += "&country=all"
37
- 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
- if count == max:
44
- return result
45
- proxy = [ip.strip(), protocol, "all"]
46
- if checkProxy(proxy, []):
47
- result.append({proxy[1]: proxy[0]})
48
- count += 1
49
- return result
50
-
51
-
52
- Providers = [Proxyscrape, Scrapingant]
File without changes
File without changes