swiftshadow 1.0.2__tar.gz → 1.1.0__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {swiftshadow-1.0.2/swiftshadow.egg-info → swiftshadow-1.1.0}/PKG-INFO +1 -1
- {swiftshadow-1.0.2 → swiftshadow-1.1.0}/setup.py +1 -1
- {swiftshadow-1.0.2 → swiftshadow-1.1.0}/swiftshadow/cache.py +0 -1
- {swiftshadow-1.0.2 → swiftshadow-1.1.0}/swiftshadow/classes.py +28 -40
- {swiftshadow-1.0.2 → swiftshadow-1.1.0}/swiftshadow/helpers.py +0 -9
- {swiftshadow-1.0.2 → swiftshadow-1.1.0/swiftshadow.egg-info}/PKG-INFO +1 -1
- {swiftshadow-1.0.2 → swiftshadow-1.1.0}/LICENSE +0 -0
- {swiftshadow-1.0.2 → swiftshadow-1.1.0}/README.md +0 -0
- {swiftshadow-1.0.2 → swiftshadow-1.1.0}/setup.cfg +0 -0
- {swiftshadow-1.0.2 → swiftshadow-1.1.0}/swiftshadow/__init__.py +0 -0
- {swiftshadow-1.0.2 → swiftshadow-1.1.0}/swiftshadow/constants.py +0 -0
- {swiftshadow-1.0.2 → swiftshadow-1.1.0}/swiftshadow/providers.py +0 -0
- {swiftshadow-1.0.2 → swiftshadow-1.1.0}/swiftshadow.egg-info/SOURCES.txt +0 -0
- {swiftshadow-1.0.2 → swiftshadow-1.1.0}/swiftshadow.egg-info/dependency_links.txt +0 -0
- {swiftshadow-1.0.2 → swiftshadow-1.1.0}/swiftshadow.egg-info/requires.txt +0 -0
- {swiftshadow-1.0.2 → swiftshadow-1.1.0}/swiftshadow.egg-info/top_level.txt +0 -0
@@ -19,7 +19,7 @@ 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.0
|
22
|
+
version="1.1.0",
|
23
23
|
packages=find_packages(where=".", exclude=["tests"]),
|
24
24
|
install_requires=["requests"],
|
25
25
|
classifiers=[
|
@@ -1,10 +1,17 @@
|
|
1
1
|
from requests import get
|
2
2
|
from random import choice
|
3
3
|
from json import dump, load
|
4
|
-
from swiftshadow.helpers import log
|
5
4
|
from swiftshadow.providers import Proxyscrape, Scrapingant, Providers
|
6
5
|
import swiftshadow.cache as cache
|
7
|
-
import
|
6
|
+
import logging
|
7
|
+
import sys
|
8
|
+
|
9
|
+
logger = logging.getLogger("swiftshadow")
|
10
|
+
logger.setLevel(logging.INFO)
|
11
|
+
logFormat = logging.Formatter("%(asctime)s - %(name)s [%(levelname)s]:%(message)s")
|
12
|
+
streamhandler = logging.StreamHandler(stream=sys.stdout)
|
13
|
+
streamhandler.setFormatter(logFormat)
|
14
|
+
logger.addHandler(streamhandler)
|
8
15
|
|
9
16
|
|
10
17
|
class Proxy:
|
@@ -16,6 +23,8 @@ class Proxy:
|
|
16
23
|
autoRotate: bool = False,
|
17
24
|
cachePeriod: int = 10,
|
18
25
|
cacheFolder: str = "",
|
26
|
+
debug: bool = False,
|
27
|
+
logToFile: bool = False,
|
19
28
|
):
|
20
29
|
"""
|
21
30
|
The one class for everything.
|
@@ -29,6 +38,8 @@ class Proxy:
|
|
29
38
|
autoRotate: Rotates proxy when `Proxy.proxy()` function is called.
|
30
39
|
cachePeriod: Time to cache proxies in minutes.
|
31
40
|
cacheFolder: Folder to store cache file.
|
41
|
+
debug: Sets Log Level to Debug.
|
42
|
+
logToFile: Whether to pipe log to a log file. If cacheFolder is set log file is saved there.
|
32
43
|
|
33
44
|
Returns:
|
34
45
|
proxyClass (swiftshadow.Proxy): `swiftshadow.Proxy` class instance
|
@@ -51,7 +62,16 @@ class Proxy:
|
|
51
62
|
self.cacheFilePath = ".swiftshadow.json"
|
52
63
|
else:
|
53
64
|
self.cacheFilePath = f"{cacheFolder}/.swiftshadow.json"
|
54
|
-
|
65
|
+
if debug:
|
66
|
+
logger.setLevel(logging.DEBUG)
|
67
|
+
if logToFile:
|
68
|
+
if cacheFolder == "":
|
69
|
+
logFilePath = "swiftshadow.log"
|
70
|
+
else:
|
71
|
+
logFilePath = f"{cacheFolder}/swiftshadow.log"
|
72
|
+
fileHandler = logging.FileHandler(logFilePath)
|
73
|
+
fileHandler.setFormatter(logFormat)
|
74
|
+
logger.addHandler(fileHandler)
|
55
75
|
self.update()
|
56
76
|
|
57
77
|
def checkIp(self, ip, cc, protocol):
|
@@ -75,8 +95,7 @@ class Proxy:
|
|
75
95
|
self.expiry = data[0]
|
76
96
|
expired = cache.checkExpiry(self.expiry)
|
77
97
|
if not expired:
|
78
|
-
|
79
|
-
"info",
|
98
|
+
logger.info(
|
80
99
|
"Loaded proxies from cache",
|
81
100
|
)
|
82
101
|
self.proxies = data[1]
|
@@ -84,12 +103,11 @@ class Proxy:
|
|
84
103
|
self.current = self.proxies[0]
|
85
104
|
return
|
86
105
|
else:
|
87
|
-
|
88
|
-
"
|
89
|
-
"Cache expired. Updating cache...",
|
106
|
+
logger.info(
|
107
|
+
"Cache expired. Updating cache.",
|
90
108
|
)
|
91
109
|
except FileNotFoundError:
|
92
|
-
|
110
|
+
logger.info("No cache found. Cache will be created after update")
|
93
111
|
|
94
112
|
self.proxies = []
|
95
113
|
self.proxies.extend(Proxyscrape(self.maxProxies, self.countries, self.protocol))
|
@@ -98,8 +116,7 @@ class Proxy:
|
|
98
116
|
Scrapingant(self.maxProxies, self.countries, self.protocol)
|
99
117
|
)
|
100
118
|
if len(self.proxies) == 0:
|
101
|
-
|
102
|
-
"warning",
|
119
|
+
logger.warning(
|
103
120
|
"No proxies found for current settings. To prevent runtime error updating the proxy list again.",
|
104
121
|
)
|
105
122
|
self.update()
|
@@ -134,32 +151,3 @@ class Proxy:
|
|
134
151
|
return choice(self.proxies)
|
135
152
|
else:
|
136
153
|
return self.current
|
137
|
-
|
138
|
-
|
139
|
-
class ProxyChains:
|
140
|
-
def __init__(
|
141
|
-
self, countries: list = [], protocol: str = "http", maxProxies: int = 10
|
142
|
-
):
|
143
|
-
self.countries = [i.upper() for i in countries]
|
144
|
-
self.protocol = protocol
|
145
|
-
self.maxProxies = maxProxies
|
146
|
-
self.update()
|
147
|
-
|
148
|
-
def update(self):
|
149
|
-
proxies = []
|
150
|
-
for provider in Providers:
|
151
|
-
print(len(proxies))
|
152
|
-
if len(proxies) == self.maxProxies:
|
153
|
-
break
|
154
|
-
log("INFO", f"{provider}")
|
155
|
-
for proxyDict in provider(self.maxProxies, self.countries, self.protocol):
|
156
|
-
proxyRaw = list(proxyDict.items())[0]
|
157
|
-
proxy = f'{proxyRaw[0]} {proxyRaw[1].replace(":"," ")}'
|
158
|
-
proxies.append(proxy)
|
159
|
-
proxies = "\n".join(proxies)
|
160
|
-
configFileName = "swiftshadow-proxychains.conf"
|
161
|
-
config = f"random_chain\nchain_len=1\nproxy_dns\n[ProxyList]\n{proxies}"
|
162
|
-
with open(configFileName, "w") as file:
|
163
|
-
file.write(config)
|
164
|
-
cmd = f"proxychains -f {os.path.abspath(configFileName)}"
|
165
|
-
os.system(cmd)
|
@@ -1,6 +1,5 @@
|
|
1
1
|
from swiftshadow.constants import CountryCodes
|
2
2
|
from requests import get
|
3
|
-
from datetime import datetime
|
4
3
|
|
5
4
|
|
6
5
|
def getCountryCode(countryName):
|
@@ -23,12 +22,4 @@ def checkProxy(proxy, countries):
|
|
23
22
|
return True
|
24
23
|
return False
|
25
24
|
except Exception as e:
|
26
|
-
# log('error',str(e))
|
27
25
|
return False
|
28
|
-
|
29
|
-
|
30
|
-
def log(level, message):
|
31
|
-
level = level.upper()
|
32
|
-
print(
|
33
|
-
f'{datetime.now().strftime("%d/%m/%Y %H:%M:%S")} - [swiftshadow] - {level} : {message}'
|
34
|
-
)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|