From a21e57f0361758f14198596797c539f63a979601 Mon Sep 17 00:00:00 2001 From: Louis_45 Date: Sun, 28 Apr 2024 17:02:48 +0200 Subject: [PATCH] Improved stability for running inside docker and improved api usage --- run.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/run.py b/run.py index 48cea4a..3485be8 100644 --- a/run.py +++ b/run.py @@ -3,15 +3,21 @@ import logging import os -apikey = os.environ['APIKEY'] -delay = int(os.environ['DELAY']) +apikey, delay = os.environ['APIKEY'], int(os.environ['DELAY']) +last_ip = "" while True: ip = requests.get("https://api.ipify.org").text - response = requests.post("https://proxy.webshare.io/api/proxy/config/", - json={"authorized_ips": [ip]}, - headers={"Authorization": apikey}) - logging.warning('Set IP to: ' + ip) - del ip - del response - time.sleep(delay) + if ip != last_ip: + response = requests.post("https://proxy.webshare.io/api/proxy/config/", + json={"authorized_ips": [ip]}, + headers={"Authorization": apikey}) + if response.status_code == 200: + if response.json()["authorized_ips"][0] == ip: + logging.warning("Successfully updated ip to: " + ip) + else: + logging.warning("Ip didn't update to " + ip + " for some reason") + else: + logging.warning("Received " + response.status_code + " error while updating ip to: " + ip) + last_ip = ip + time.sleep(delay) \ No newline at end of file