From 367a087e0771433f3fc8de288979c815b3e77dec Mon Sep 17 00:00:00 2001 From: Maurice Berk Date: Mon, 26 Jul 2021 09:14:30 +0100 Subject: [PATCH] Add header to market book table --- betfairviz/__init__.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/betfairviz/__init__.py b/betfairviz/__init__.py index a7a8747..c46a353 100644 --- a/betfairviz/__init__.py +++ b/betfairviz/__init__.py @@ -1,3 +1,4 @@ +import datetime import itertools from enum import Enum from html import escape @@ -24445,7 +24446,38 @@ def _create_market_book_table( if type(market_book) != dict: market_book = market_book._data selection_count = sum(1 for r in market_book['marketDefinition']['runners'] if r['status'] != 'REMOVED') + publish_time_as_datetime = datetime.datetime.utcfromtimestamp(market_book['publishTime'] / 1000) + market_time_date_as_datetime = datetime.datetime.strptime(market_book['marketDefinition']['marketTime'], '%Y-%m-%dT%H:%M:%S.%fZ') + + if publish_time_as_datetime < market_time_date_as_datetime: + relative_time_string = f'{market_time_date_as_datetime - publish_time_as_datetime} until marketTime' + else: + relative_time_string = f'{publish_time_as_datetime - market_time_date_as_datetime} since marketTime' + title = market_book['marketDefinition']['eventName'] + if 'name' in market_book['marketDefinition']: + title += market_book['marketDefinition']['name'] html = f""" +
+
+
+ + {title} + +
+ + {publish_time_as_datetime}: {relative_time_string} + +
+
+ + Market is {market_book['marketDefinition']['status']} + +
+
+
+
+
+