PKMO6Dbmrs.py"""This package enables you receive BMRS data as json instead of the default XML""" __version__ = '1.2.2' from time import sleep, time import stomp import xmltodict import json class MyListener(stomp.ConnectionListener): '''This is a listener class that listens for new messages using the STOMP protocol''' def __init__(self, listener): self.listener = listener def on_error(self, headers, message): print(f'ERROR! : "{message}"') def on_message(self, headers, message): message = xmltodict.parse(message) for key,value in headers.items(): message[key]=value # print('header: key %s , value %s' %(key, value)) message = json.loads(json.dumps(message)) self.listener(message) def connect_to_api(api_key='', client_id='', listener='', port=61613): ''' Connect to the BMRS API. This function will get the XML data and convert it to JSON instantaneoudly! `api_key`: is your API key that can be got by following [Guide](https://www.elexon.co.uk/documents/training-guidance/bsc-guidance-notes/bmrs-api-and-data-push-user-guide-2/). `client_id`: is your Client ID that can be got together with the APIkey from the above step. `listener`: is your custom function that recieves & handles messages returned from the API. See a sample of this in our sample file sample_client.py on github. ''' # connect to API using stomp conn = stomp.Connection12( host_and_ports=[ ('api.bmreports.com', port)], use_ssl=True) conn.start() conn.connect(api_key, api_key, True) conn.subscribe( destination='/topic/bmrsTopic', ack='auto', id=client_id) # add a listener instance and initialize it with the user's supplied custom listener conn.set_listener('', MyListener(listener)) # check for new meessages after every x seconds while conn.is_connected(): sleep(1) PKjUN`.;;bmrs-1.2.2.dist-info/LICENSEThe MIT License (MIT) Copyright (c) 2019 Edison Abahurire Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HPObmrs-1.2.2.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,szd&Y)r$[)T&UrPK!H4D?bmrs-1.2.2.dist-info/METADATAmU]OF}_q} >Dj Ym"mW &gAȿqBn{ܯsϽa/KON=LLeCZ6։<;4nt_)G,^䚉\hkY.X2~s7蚤gg4)<˒̊|TJ7ixՐ*[7UXfijԥ)9 lVk_S1 2vHRxUwn$q :@`z),V .~"7lsj'VrIP*pHWʵivWCD'4j[k^adfʦQzMRC]޴siyKbZZiwrcʀhR4i=}siڬ z ޔ* V+d+(VUji[ a;5zَetS-!v#\BJNlgf~R|}K~VԘqP%""XkPIB+vvLyb3NhX*br ٦N-K\SV-!k;(Y#񷨰F؝D#!)6r.@7ʺ(Vf M%}'Z0u#L:Gĕ 6݇qס2jgNIeW|bbDoT{uu[bm=Ph\GY11IP_b#q,2](Cb֭2IH_jAըT2ub\iޖ|k L p/PK!HZbmrs-1.2.2.dist-info/RECORDu˒C@}F\衉\Ku#O?6v::Iꋘ=jͣFn#RhĸfA1005S@]4سҲΚPA*"ܥGL.CmU7YR% 0?DSEG-yp2!U.Q4 .9#J߃r ]|',^]B0w dX9o0ѷ^rUPKMO6Dbmrs.pyPKjUN`.;;bmrs-1.2.2.dist-info/LICENSEPK!HPO1 bmrs-1.2.2.dist-info/WHEELPK!H4D? bmrs-1.2.2.dist-info/METADATAPK!HZ3bmrs-1.2.2.dist-info/RECORDPK[_