Skip to content

Commit

Permalink
Improved stability for running inside docker and improved api usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis_45 committed Apr 28, 2024
1 parent d8121e6 commit a21e57f
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit a21e57f

Please sign in to comment.