Skip to content

Commit

Permalink
Bump to 1.10, pin websocket-client, and add --url parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Fitblip committed Sep 20, 2018
1 parent 68a983c commit abd9e79
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
3 changes: 2 additions & 1 deletion certstream/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
parser.add_argument('--full', action='store_true', help='Output all SAN addresses as well')
parser.add_argument('--disable-colors', action='store_true', help='Disable colors when writing a human readable ')
parser.add_argument('--verbose', action='store_true', default=False, dest='verbose', help='Display debug logging.')
parser.add_argument('--url', default="wss://certstream.calidog.io", dest='url', help='Connect to a certstream server.')

def main():
args = parser.parse_args()
Expand Down Expand Up @@ -60,7 +61,7 @@ def _handle_messages(message, context):

sys.stdout.flush()

certstream.listen_for_events(_handle_messages, skip_heartbeats=True)
certstream.listen_for_events(_handle_messages, args.url, skip_heartbeats=True)

if __name__ == "__main__":
main()
9 changes: 4 additions & 5 deletions certstream/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ class Context(dict):
__delattr__ = dict.__delitem__

class CertStreamClient(WebSocketApp):
CERTSTREAM_URL = 'wss://certstream.calidog.io'
_context = Context()

def __init__(self, message_callback, skip_heartbeats=True, on_open=None, on_error=None):
def __init__(self, message_callback, url, skip_heartbeats=True, on_open=None, on_error=None):
self.message_callback = message_callback
self.skip_heartbeats = skip_heartbeats
self.on_open_handler = on_open
self.on_error_handler = on_error
super(CertStreamClient, self).__init__(
url=self.CERTSTREAM_URL,
url=url,
on_open=self._on_open,
on_message=self._on_message,
on_error=self._on_error,
Expand All @@ -48,13 +47,13 @@ def _on_error(self, instance, ex):
self.on_error_handler(instance, ex)
logging.error("Error connecting to CertStream - {} - Sleeping for a few seconds and trying again...".format(ex))

def listen_for_events(message_callback, skip_heartbeats=True, setup_logger=True, on_open=None, on_error=None, **kwargs):
def listen_for_events(message_callback, url, skip_heartbeats=True, setup_logger=True, on_open=None, on_error=None, **kwargs):
if setup_logger:
logging.basicConfig(format='[%(levelname)s:%(name)s] %(asctime)s - %(message)s', level=logging.INFO)

try:
while True:
c = CertStreamClient(message_callback, skip_heartbeats=skip_heartbeats, on_open=on_open, on_error=on_error)
c = CertStreamClient(message_callback, url, skip_heartbeats=skip_heartbeats, on_open=on_open, on_error=on_error)
c.run_forever(**kwargs)
time.sleep(5)
except KeyboardInterrupt:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
websocket-client
websocket-client==0.48.0
termcolor
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

setup(
name='certstream',
version="1.9",
version="1.10",
url='https://github.com/CaliDog/certstream-python/',
author='Ryan Sears',
install_requires=dependencies,
Expand Down

0 comments on commit abd9e79

Please sign in to comment.