2024-05-19 00:42:36 +00:00
|
|
|
import time
|
|
|
|
import requests
|
2024-06-09 17:38:32 +00:00
|
|
|
import json
|
2024-05-19 00:42:36 +00:00
|
|
|
from threading import Thread
|
|
|
|
|
2024-06-09 17:38:32 +00:00
|
|
|
|
2024-05-19 00:42:36 +00:00
|
|
|
class ApiHandler:
|
|
|
|
def identify_btclock(self, address):
|
|
|
|
self.make_api_call(address, "api/identify")
|
|
|
|
return
|
2024-06-09 17:38:32 +00:00
|
|
|
|
2024-05-19 00:42:36 +00:00
|
|
|
def check_fs_hash(self, address):
|
|
|
|
ret = self.run_api_call(address, "fs_hash.txt")
|
|
|
|
return ret
|
|
|
|
|
2024-06-09 17:38:32 +00:00
|
|
|
def get_settings(self, address):
|
|
|
|
ret = json.loads(self.run_api_call(address, "api/settings"))
|
|
|
|
return ret
|
|
|
|
|
2024-05-19 00:42:36 +00:00
|
|
|
def make_api_call(self, address, path):
|
2024-06-09 17:38:32 +00:00
|
|
|
thread = Thread(target=self.run_api_call, args=(address, path))
|
2024-05-19 00:42:36 +00:00
|
|
|
thread.start()
|
|
|
|
|
|
|
|
def run_api_call(self, address, path):
|
|
|
|
try:
|
|
|
|
url = f"http://{address}/{path}"
|
|
|
|
response = requests.get(url)
|
|
|
|
return response.text
|
|
|
|
except requests.RequestException as e:
|
2024-06-09 17:38:32 +00:00
|
|
|
print("error")
|