From 70bc4f8ae08ddb46924ca967e068e56040bae49c Mon Sep 17 00:00:00 2001 From: CMDR furrycat Date: Tue, 11 Apr 2017 11:34:07 +0100 Subject: [PATCH] Added parse_iso8601(). --- bot.py | 3 +++ eddn.py | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/bot.py b/bot.py index f4ccef4..29ac971 100644 --- a/bot.py +++ b/bot.py @@ -666,6 +666,9 @@ async def set_role(member, role, minimum = 1): def iso8601(timestamp): return datetime.datetime.utcfromtimestamp(timestamp).isoformat()[:19] + 'Z' +def parse_iso8601(string): + return int(datetime.datetime.strptime(string, '%Y-%m-%dT%H:%M:%SZ').timestamp()) + def ago(timestamp): now = int(time.time()) if now < timestamp: diff --git a/eddn.py b/eddn.py index 4661e31..cab01c5 100644 --- a/eddn.py +++ b/eddn.py @@ -1,14 +1,16 @@ import asyncio import json import logging +import re import zlib import zmq import zmq.asyncio log = logging.getLogger('eddn') -url = 'tcp://eddn-relay.elite-markets.net:9500' -topic = b'' +url = 'tcp://eddn-gateway.elite-markets.net:9500' +schema_prefix = 'http://schemas.elite-markets.net/eddn' +topics = ['{}/{}/{}'.format(schema_prefix, 'journal', 1)] timeout = 600000 async def listen(plugins): @@ -17,8 +19,14 @@ async def listen(plugins): while True: try: subscriber = context.socket(zmq.SUB) + log.info('Connecting to {}'.format(url)) subscriber.connect(url) - subscriber.setsockopt(zmq.SUBSCRIBE, topic) + if len(topics): + for topic in topics: + log.info('Subscribing to {}'.format(topic)) + subscriber.setsockopt(zmq.SUBSCRIBE, topic.encode('utf-8')) + else: + subscriber.setsockopt(zmq.SUBSCRIBE, b'') subscriber.setsockopt(zmq.RCVTIMEO, timeout) poller = zmq.asyncio.Poller() poller.register(subscriber, zmq.POLLOUT) @@ -51,3 +59,7 @@ async def decode_message(compressed): except ValueError: log.exception('Malformed JSON in message') return None + +def is_schema(schema, namespace, *, version = None, test = False): + regex = '^{}/{}/{}{}$'.format(schema_prefix, namespace, version if version is not None else '\d+', '/test' if test else '').encode('string-escape') + return bool(re.match(regex, schema)) -- 2.7.4