SHARE
TWEET

Untitled

a guest Feb 18th, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. import asyncio
  5. import json
  6. import zlib
  7. import zmq
  8. import zmq.asyncio
  9.  
  10.  
  11. SOCKET_URI = "tcp://eddn.edcd.io:9500"
  12.  
  13. ALLOWED_SCHEMA = (
  14.     # "https://eddn.edcd.io/schemas/blackmarket/1",
  15.     # "https://eddn.edcd.io/schemas/commodity/3",
  16.     "https://eddn.edcd.io/schemas/journal/1",
  17.     # "https://eddn.edcd.io/schemas/outfitting/2",
  18.     # "https://eddn.edcd.io/schemas/shipyard/2",
  19. )
  20.  
  21. ALLOWED_EVENTS = (
  22.     "FSDJump",
  23.     "Scan",
  24. )
  25.  
  26.  
  27. ctx = zmq.asyncio.Context.instance()
  28.  
  29.  
  30. async def main():
  31.     sock = ctx.socket(zmq.SUB)
  32.     sock.connect(SOCKET_URI)
  33.     sock.subscribe(b"")
  34.  
  35.     while True:
  36.         raw, = await sock.recv_multipart()
  37.  
  38.         try:
  39.             ref, _, msg, = json.loads(zlib.decompress(raw)).values()
  40.  
  41.             if ref in ALLOWED_SCHEMA:
  42.                 if msg["event"] in ALLOWED_EVENTS:
  43.                     sys_id64 = msg["SystemAddress"]
  44.                     body_id = msg.get("BodyID") or 0
  45.                     body_id64 = sys_id64 + (body_id << 55)
  46.  
  47.                     sys_name = msg["StarSystem"]
  48.                     body_name = msg.get("BodyName") or "<None>"
  49.  
  50.                     print(f"{sys_name:<40} -> {body_name:<40}")
  51.         except Exception as exc:
  52.             print(exc)
  53.  
  54.     sock.close()
  55.  
  56.  
  57. if __name__ == "__main__":
  58.     loop = asyncio.get_event_loop()
  59.     try:
  60.         loop.run_until_complete(main())
  61.     except KeyboardInterrupt:
  62.         pass
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top