Skip to content

Commit

Permalink
Allowing log_level to be set during instantiation of RequestProxy (#68)…
Browse files Browse the repository at this point in the history
… (#67)

* Allowing log_level to be set during instantiation of RequestProxy

* Bump version to 1.3.2
  • Loading branch information
broglea authored Nov 15, 2020
1 parent 5abec6d commit 26d8cb7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ To use **http-request-randomizer** as a library, include it in your requirements
Then you can simply generate a proxied request using a method call:

````python
import logging
import time
from http_request_randomizer.requests.proxy.requestProxy import RequestProxy

if __name__ == '__main__':

start = time.time()
req_proxy = RequestProxy()
req_proxy = RequestProxy(log_level=logging.ERROR)
print("Initialization took: {0} sec".format((time.time() - start)))
print("Size: {0}".format(len(req_proxy.get_proxy_list())))
print("ALL = {0} ".format(list(map(lambda x: x.get_address(), req_proxy.get_proxy_list()))))
Expand All @@ -118,6 +119,9 @@ if __name__ == '__main__':
time.sleep(10)
````

### Changing log levels
The `RequestProxy` constructor accepts an optional parameter of `log_level` that can be used to change the level of logging. By default, this is equal to 0, or NOTSET. The python logging levels are documented [here](https://docs.python.org/3/library/logging.html#logging-levels). You can either use integers or their equivalent constant in the logging module. (e.g. `logging.DEBUG`, `logging.ERROR`, etc)

## Documentation

[http-request-randomizer documentation](https://pgaref.com/HTTP_Request_Randomizer)
Expand Down
4 changes: 2 additions & 2 deletions http_request_randomizer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__author__ = 'pgaref'

__version__ = '1.2.3'
__version__ = '1.3.2'

__title__ = 'http_request_randomizer'
__description__ = 'A package using public proxies to randomise http requests'
Expand All @@ -10,4 +10,4 @@
__email__ = '[email protected]'

__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 ' + __author__
__copyright__ = 'Copyright (c) 2020 ' + __author__
4 changes: 2 additions & 2 deletions http_request_randomizer/requests/proxy/requestProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@


class RequestProxy:
def __init__(self, web_proxy_list=[], sustain=False, timeout=5, protocol=Protocol.HTTP):
def __init__(self, web_proxy_list=[], sustain=False, timeout=5, protocol=Protocol.HTTP, log_level=0):
self.logger = logging.getLogger()
self.logger.addHandler(handler)
self.logger.setLevel(0)
self.logger.setLevel(log_level)
self.userAgent = UserAgentManager(file=os.path.join(os.path.dirname(__file__), '../data/user_agents.txt'))

#####
Expand Down

0 comments on commit 26d8cb7

Please sign in to comment.