swiftshadow 1.0.1__tar.gz → 1.1.0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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.1",
22
+ version="1.1.0",
23
23
  packages=find_packages(where=".", exclude=["tests"]),
24
24
  install_requires=["requests"],
25
25
  classifiers=[
@@ -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):
@@ -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)
@@ -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,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
File without changes
File without changes
File without changes