can get device id

This commit is contained in:
bj
2021-01-28 15:33:21 +02:00
parent 3c0eece311
commit 3d90ed0708
8 changed files with 196 additions and 22 deletions
+9 -2
View File
@@ -1,10 +1,17 @@
from syncthing_monitor.config_xml import parse_api_key
from syncthing_monitor.config_xml import parse_api_key, set_listen_ip_to_any
from syncthing_monitor.syncthing_rest import get_device_id
def loop():
def loop(gui_port="8384", host="sync"):
api_key = parse_api_key()
print("Found API Key: {0}".format(api_key))
set_listen_ip_to_any()
device_id = get_device_id(host, gui_port, api_key)
print("Found Device ID: {0}".format(device_id))
if __name__ == "__main__":
loop()
+10
View File
@@ -8,3 +8,13 @@ def parse_api_key(xml_path='/config/config.xml'):
# noinspection SpellCheckingInspection
api_key = gui.find('apikey').text
return api_key
def set_listen_ip_to_any(in_xml_path='/config/config.xml', out_xml_path='/config/config.xml', gui_port='8384'):
with open(in_xml_path, 'r') as file:
xml = file.read()
xml = xml.replace("127.0.0.1:8384", "0.0.0.0:"+gui_port)
with open(out_xml_path, 'w') as file:
file.write(xml)
+11
View File
@@ -0,0 +1,11 @@
import json
import requests
from retrying import retry
@retry
def get_device_id(host, gui_port, api_key):
syncthing_headers = {'X-API-Key': api_key}
response = requests.get("http://" + host + ":" + gui_port + "/rest/system/status", headers=syncthing_headers)
return json.loads(response.content)["myID"]