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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,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 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)
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
- log(
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
- log(
88
- "info",
89
- "Cache expired. Updating cache...",
106
+ logger.info(
107
+ "Cache expired. Updating cache.",
90
108
  )
91
109
  except FileNotFoundError:
92
- log("error", "No cache found. Cache will be created after update")
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
- log(
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)
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
- )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: swiftshadow
3
- Version: 1.0.2
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=WSSZFwfRWuF2r0X0fb-J4IigmZkxox5EOr8uQQr0SWM,5773
4
- swiftshadow/constants.py,sha256=FRhoYg8WNaLy8RLDD4BsANlXlY2tctBCdy7sCnkaVY0,6303
5
- swiftshadow/helpers.py,sha256=C3iekcwN3ni4pFx0rV7EPYPqDglHCHMTtbWMPNNnOX8,917
6
- swiftshadow/providers.py,sha256=GaVKg5J5hH2HSfdGDPuFivcCu6QB5HFjlVFvrrtNdhw,1490
7
- swiftshadow-1.0.2.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
8
- swiftshadow-1.0.2.dist-info/METADATA,sha256=zSImGEjSvlwxYj_h11atv5iHNaaZ25Eog50ft4ClcNo,2635
9
- swiftshadow-1.0.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
10
- swiftshadow-1.0.2.dist-info/top_level.txt,sha256=GClzVDF5vWSzqHOwgG2ycQAAJXRxd-QOdP1h3YrHOuM,12
11
- swiftshadow-1.0.2.dist-info/RECORD,,