PKcN|bmrs.py"""This package that enables you fetch BMRS data as json instead of XML""" __version__ = '1.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 https://www.elexon.co.uk/wp-content/uploads/2017/06/bmrs_api_data_push_user_guide_v1.1.pdf client_id: is your Client ID that can be got by following https://www.elexon.co.uk/wp-content/uploads/2017/06/bmrs_api_data_push_user_guide_v1.1.pdf 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.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.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,szd&Y)r$[)T&UrPK!H3#bmrs-1.2.dist-info/METADATAmUn"G}(il$3h;{8MN"Ynf eb  :U\sr')87RsI3x?.N$i-FrZSld$6rrM4X5o^5L,ksJf5F~#@ʈV2\8ՊMTtZt75d%8__>l{&w.Z]IHx=T'vW6by:rm`P!Tʺl>@HCn H›nU{8>)> *~!ʶNǐTӓS-kqNʎ،0Tn\Dz~~dA7-]w]A7}MmM3ߤ $ T8ͽմj1J!+wmJpi8 PYyNL5ԑa.eU9>NŪ-sdt(V+[Peiu8 և~L$Tl v.#ՒrO{p*5hdDiS㰋_8L`ڪ$g+U-;NU _N alV'w6of)"?q|K<+n<Zj0SR!$4YЕV%tsq"Zr^ q;!NO}qYqɺ4sآq„Sn@֮@j-Mj4vrȫHmnz vna N61 sgR5m/L7aU=PK!HXQzRbmrs-1.2.dist-info/RECORDm9@@ܳ4L7LЅ j!P,@ ,ĉ8ӖPhpmLzz3dY@D\t߱"SR~ b96T]٦/.I8^nƃK]ehh_ 7ƱEGLr! 9W}?ϣk0-类Տ8CȘx΢) ]c<8= $)p˼azؽPKcN|bmrs.pyPKjUN`.;;bmrs-1.2.dist-info/LICENSEPK!HPO9 bmrs-1.2.dist-info/WHEELPK!H3# bmrs-1.2.dist-info/METADATAPK!HXQzRbmrs-1.2.dist-info/RECORDPKS