Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from __future__ import print_function
- import sys
- import time
- import pprint
- from satori.rtm.client import make_client, SubscriptionMode
- endpoint = "wss://open-data.api.satori.com"
- appkey = "5Ba8Bf20bbAaaf1EDBA997E63AF4a78f"
- channel = "new-zealand"
- messages = []
- ids = []
- def to_conduce(messages):
- existing_ents = []
- new_ents = []
- for message in messages:
- ent = {"identity":message['vehicleId'],
- "timestamp_ms": int(message['lastLocationUpdateTime']),
- "endtime_ms": int(message['lastLocationUpdateTime']+86400000),
- "kind": "new-zealand",
- "path": [{"y":float(message['location']['lon']),"x":float(message['location']['lat']),"z":float(0.0)}],
- "attrs": json.dumps(message)
- }
- if message['vehicleId'] in vehicle_ids:
- existing_ents.append(ent)
- else:
- new_ents.append(ent)
- r = requests.post('some url')
- print(r.text)
- r = requests.post('some url')
- print(r.text)
- messages = []
- def main():
- messages = []
- with make_client(endpoint=endpoint, appkey=appkey) as client:
- print('Connected to Satori RTM!')
- class SubscriptionObserver(object):
- def on_subscription_data(self, data):
- for message in data['messages']:
- print(message['entity'].keys())
- messages.append(message)
- if len(messages)>1000:
- to_conduce(messages)
- messages = []
- subscription_observer = SubscriptionObserver()
- client.subscribe(
- channel,
- SubscriptionMode.SIMPLE,
- subscription_observer)
- try:
- while True:
- time.sleep(1)
- except KeyboardInterrupt:
- pass
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement