Save P+ connect response

This commit is contained in:
Taylor Helsper 2022-07-22 21:53:17 -05:00
parent 3697888c02
commit 0c3786c620

View File

@ -99,6 +99,11 @@ def on_connect_success(connect_response_data):
log_message("on_connect_success exception: {}".format(str(e)))
return
def clear_response_data():
os.system("rm -f /tmp/premium_plus_response.json")
def save_response_data(data):
with open("/tmp/premium_plus_response.json", "w") as file:
json.dump(data, file, indent=4, sort_keys=True)
# Update hourly
def premium_plus_connect():
@ -118,11 +123,13 @@ def premium_plus_connect():
response = make_tor_request(PREMIUM_PLUS_CONNECT_URL, data)
update_premium_plus_last_sync_time()
if response == None:
clear_response_data()
set_premium_plus_token_status("CONNECTION_ERROR")
log_message("Premium+ Connect Error: Connection Failed")
return False
if response.status_code != 200:
clear_response_data()
set_premium_plus_token_status("CONNECTION_ERROR")
log_message("Premium+ Connect Error: Status Code {}".format(response.status_code))
return False
@ -133,6 +140,8 @@ def premium_plus_connect():
log_message("Premium+ Connect Error: Error Parsing JSON - {}".format(str(e)))
return False
save_response_data(info)
if "error" in info:
set_premium_plus_token_status(info["error"])
return False