Last active
February 24, 2020 16:07
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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