Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. import json
  2.  
  3. from redis import StrictRedis
  4.  
  5. redis_client = StrictRedis()
  6. redis_pubsub = redis_client.pubsub(ignore_subscribe_messages=True)
  7.  
  8. class TerminalColor:
  9.     HEADER = '\033[95m'
  10.     OKBLUE = '\033[94m'
  11.     OKGREEN = '\033[92m'
  12.     WARNING = '\033[93m'
  13.     FAIL = '\033[91m'
  14.     ENDC = '\033[0m'
  15.     BOLD = '\033[1m'
  16.     UNDERLINE = '\033[4m'
  17.  
  18. def on_warrior_message(message):
  19.     data = json.loads(message["data"])
  20.  
  21.     # Split the message
  22.     output_split = data["data"].split(" ")
  23.  
  24.     # Change the color depending on status.
  25.     if "=404" in output_split[0]:
  26.         status_color = TerminalColor.FAIL
  27.     elif "=301" in output_split[0]:
  28.         status_color = TerminalColor.WARNING
  29.     else:
  30.         status_color = TerminalColor.OKGREEN
  31.  
  32.     print("[{status_color}{host}:{port}{endc}]\t {data}{endc}".format(
  33.         host=data["host"],
  34.         port=data["port"],
  35.         data=data["data"].strip(),
  36.         # Colors
  37.         status_color=status_color,
  38.         endc=TerminalColor.ENDC
  39.     ))
  40.  
  41. redis_pubsub.subscribe(**{"tumblr:warrior": on_warrior_message})
  42. pubsub_thread = redis_pubsub.run_in_thread(sleep_time=0.001)
  43.  
  44. try:
  45.     pubsub_thread.join()
  46. except KeyboardInterrupt:
  47.     pubsub_thread.stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement