Skip to content

Instantly share code, notes, and snippets.

@sehraf
Last active February 24, 2020 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sehraf/a5da366b084613cd3ac9e60a9fb01324 to your computer and use it in GitHub Desktop.
Save sehraf/a5da366b084613cd3ac9e60a9fb01324 to your computer and use it in GitHub Desktop.
Example on how to query and change max up/download rates in RetroShare using the json api.
#!/usr/bin/python3
import json, requests, re
debug = False
port = 9092
user = 'test'
pw = 'tset'
def debugDump(label, data):
if not debug: return
print(label, json.dumps(data, sort_keys=True, indent=4))
def sendRequest(function, data = None):
url = 'http://127.0.0.1:' + str(port) + function
debugDump('POST: ' + url, data)
resp = requests.post(url=url, json=data, auth=(user, pw))
# gracefully add 401 error
if resp.status_code == 401:
return {'retval': False}
debugDump('RESP', resp.json())
return resp.json()
if __name__ == "__main__":
# display current (active) up/download
resp = sendRequest('/rsConfig/GetCurrentDataRates')
print(resp)
# get current configured rates
resp = sendRequest('/rsConfig/GetMaxDataRates')
print(resp)
# save from respomse
old = {
'downKb': resp['inKb'],
'upKb': resp['outKb']
}
# setup half rates
req = {
'downKb': resp['inKb'] // 2,
'upKb': resp['outKb'] // 2
}
resp = sendRequest('/rsConfig/SetMaxDataRates', data=req)
print(resp)
resp = sendRequest('/rsConfig/GetMaxDataRates')
print(resp)
# setup old rates
resp = sendRequest('/rsConfig/SetMaxDataRates', data=old)
print(resp)
resp = sendRequest('/rsConfig/GetMaxDataRates')
print(resp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment