can get device id
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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"]
|
||||
Reference in New Issue
Block a user