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

Sign up to get free protection for your applications and to get access to all the features.
swiftshadow/cache.py CHANGED
@@ -1,5 +1,4 @@
1
1
  from datetime import datetime, timezone, timedelta
2
- from time import sleep
3
2
 
4
3
 
5
4
  def getExpiry(expiryIn):
swiftshadow/classes.py CHANGED
@@ -1,11 +1,17 @@
1
1
  from requests import get
2
2
  from random import choice
3
- from datetime import datetime, timezone, timedelta
4
3
  from json import dump, load
5
- from swiftshadow.helpers import log
6
4
  from swiftshadow.providers import Proxyscrape, Scrapingant, Providers
7
5
  import swiftshadow.cache as cache
8
- import os
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)
9
15
 
10
16
 
11
17
  class Proxy:
@@ -17,6 +23,8 @@ class Proxy:
17
23
  autoRotate: bool = False,
18
24
  cachePeriod: int = 10,
19
25
  cacheFolder: str = "",
26
+ debug: bool = False,
27
+ logToFile: bool = False,
20
28
  ):
21
29
  """
22
30
  The one class for everything.
@@ -30,6 +38,8 @@ class Proxy:
30
38
  autoRotate: Rotates proxy when `Proxy.proxy()` function is called.
31
39
  cachePeriod: Time to cache proxies in minutes.
32
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.
33
43
 
34
44
  Returns:
35
45
  proxyClass (swiftshadow.Proxy): `swiftshadow.Proxy` class instance
@@ -48,11 +58,20 @@ class Proxy:
48
58
  self.maxProxies = maxProxies
49
59
  self.autoRotate = autoRotate
50
60
  self.cachePeriod = cachePeriod
51
- if cacheFolder != "":
61
+ if cacheFolder == "":
52
62
  self.cacheFilePath = ".swiftshadow.json"
53
63
  else:
54
64
  self.cacheFilePath = f"{cacheFolder}/.swiftshadow.json"
55
-
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)
56
75
  self.update()
57
76
 
58
77
  def checkIp(self, ip, cc, protocol):
@@ -76,21 +95,19 @@ class Proxy:
76
95
  self.expiry = data[0]
77
96
  expired = cache.checkExpiry(self.expiry)
78
97
  if not expired:
79
- log(
80
- "info",
81
- f"Loaded proxies from cache",
98
+ logger.info(
99
+ "Loaded proxies from cache",
82
100
  )
83
101
  self.proxies = data[1]
84
102
  self.expiry = data[0]
85
103
  self.current = self.proxies[0]
86
104
  return
87
105
  else:
88
- log(
89
- "info",
90
- f"Cache expired. Updating cache...",
106
+ logger.info(
107
+ "Cache expired. Updating cache.",
91
108
  )
92
109
  except FileNotFoundError:
93
- log("error", "No cache found. Cache will be created after update")
110
+ logger.info("No cache found. Cache will be created after update")
94
111
 
95
112
  self.proxies = []
96
113
  self.proxies.extend(Proxyscrape(self.maxProxies, self.countries, self.protocol))
@@ -99,8 +116,7 @@ class Proxy:
99
116
  Scrapingant(self.maxProxies, self.countries, self.protocol)
100
117
  )
101
118
  if len(self.proxies) == 0:
102
- log(
103
- "warning",
119
+ logger.warning(
104
120
  "No proxies found for current settings. To prevent runtime error updating the proxy list again.",
105
121
  )
106
122
  self.update()
@@ -135,32 +151,3 @@ class Proxy:
135
151
  return choice(self.proxies)
136
152
  else:
137
153
  return self.current
138
-
139
-
140
- class ProxyChains:
141
- def __init__(
142
- self, countries: list = [], protocol: str = "http", maxProxies: int = 10
143
- ):
144
- self.countries = [i.upper() for i in countries]
145
- self.protocol = protocol
146
- self.maxProxies = maxProxies
147
- self.update()
148
-
149
- def update(self):
150
- proxies = []
151
- for provider in Providers:
152
- print(len(proxies))
153
- if len(proxies) == self.maxProxies:
154
- break
155
- log("INFO", f"{provider}")
156
- for proxyDict in provider(self.maxProxies, self.countries, self.protocol):
157
- proxyRaw = list(proxyDict.items())[0]
158
- proxy = f'{proxyRaw[0]} {proxyRaw[1].replace(":"," ")}'
159
- proxies.append(proxy)
160
- proxies = "\n".join(proxies)
161
- configFileName = "swiftshadow-proxychains.conf"
162
- config = f"random_chain\nchain_len=1\nproxy_dns\n[ProxyList]\n{proxies}"
163
- with open(configFileName, "w") as file:
164
- file.write(config)
165
- cmd = f"proxychains -f {os.path.abspath(configFileName)}"
166
- os.system(cmd)
swiftshadow/helpers.py CHANGED
@@ -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
- )
swiftshadow/providers.py CHANGED
@@ -1,5 +1,5 @@
1
1
  from requests import get
2
- from swiftshadow.helpers import getCountryCode, checkProxy, log
2
+ from swiftshadow.helpers import getCountryCode, checkProxy
3
3
 
4
4
 
5
5
  def Scrapingant(max, countries=[], protocol="http"):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: swiftshadow
3
- Version: 1.0.1
3
+ Version: 1.1.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
@@ -0,0 +1,11 @@
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,,
@@ -1,11 +0,0 @@
1
- swiftshadow/__init__.py,sha256=cybIN6hvkK06k9aeun0YhhuUSZiEcIr6jdOne2WFWlA,604
2
- swiftshadow/cache.py,sha256=2bQo7WqeyAMJkfLj4wRX5fPatZPaiaLVcn2gm_pzBFg,434
3
- swiftshadow/classes.py,sha256=JM0L--raQ3pusqWrBo7fF0UDYZPMh7zES3yOtcsp_RE,5826
4
- swiftshadow/constants.py,sha256=FRhoYg8WNaLy8RLDD4BsANlXlY2tctBCdy7sCnkaVY0,6303
5
- swiftshadow/helpers.py,sha256=C3iekcwN3ni4pFx0rV7EPYPqDglHCHMTtbWMPNNnOX8,917
6
- swiftshadow/providers.py,sha256=qsVCJPJFcKCbt-yCK63gvZufvt7J__HhfSBItyWdFt8,1495
7
- swiftshadow-1.0.1.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
8
- swiftshadow-1.0.1.dist-info/METADATA,sha256=JHHu-wXNCa-CVyGhVpDSQm7w2HWP4DVVu9jsxFxAOIY,2635
9
- swiftshadow-1.0.1.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
10
- swiftshadow-1.0.1.dist-info/top_level.txt,sha256=GClzVDF5vWSzqHOwgG2ycQAAJXRxd-QOdP1h3YrHOuM,12
11
- swiftshadow-1.0.1.dist-info/RECORD,,