Skip to content

Instantly share code, notes, and snippets.

@juandesant
Created June 26, 2013 17:36
Show Gist options
  • Save juandesant/5869531 to your computer and use it in GitHub Desktop.
Save juandesant/5869531 to your computer and use it in GitHub Desktop.
This gist shows how to use sampy to interact with different VO applications. It assumes you have sampy installed.
#!/usr/bin/env python
from sampy import *
import time
from pprint import pprint
# Setup hub by calling "start_samp_hub.py", it would contain:
# myhub = SAMPHubServer()
# myhub.start(True) # The True makes the script standalone; it should be called with
# alternatively, sampy (/usr/local/bin/sampy, for instance) can be called:
import subprocess
hubSubprocess = subprocess.Popen(["/usr/local/bin/sampy"])
client=SAMPIntegratedClient(
metadata = {
"samp.name": "client",
"samp.description.text": "python client",
"client.version":"0.01"
}
)
client.connect()
client_metadata_to_update = {
"samp.name": "Client",
"samp.description.text": "Sampy-based python client",
"client.version":"0.01"
}
client.declareMetadata(client_metadata_to_update)
# Function called when a notification is received
def test_receive_notification (private_key, sender_id, mtype, params, extra):
pprint ({
'call_type': 'Notification',
'private_key': private_key,
'sender_id': sender_id,
'mtype': mtype,
'params': params,
'extra': extra
})
# Function called when a call is received
def test_receive_call (private_key, sender_id, msg_id, mtype, params, extra):
pprint ({
'call_type': 'Call',
'private_key': private_key,
'sender_id': sender_id,
'msg_id': msg_id,
'mtype': mtype,
'params': params,
'extra': extra
})
# Needs to be defined _after_ client has been created
client.ereply(msg_id, SAMP_STATUS_OK, result = None)
# Function called when a response is received
def test_receive_response (private_key, sender_id, msg_id, response):
pprint ({
'call_type': 'Response',
'private_key': private_key,
'sender_id': sender_id,
'msg_id': msg_id,
'response': response
})
client.bindReceiveNotification("table.load.votable",test_receive_notification)
client.bindReceiveCall("table.load.votable",test_receive_call)
# client.bindReceiveResponse("table.load.votable",test_receive_notification)
# Close the client, when needed
# client.disconnect()
# Close the hub, if necessary
# hubSubprocess.terminate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment