-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
23 lines (21 loc) · 850 Bytes
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import time
import requests
import logging
import os
apikey, delay = os.environ['APIKEY'], int(os.environ['DELAY'])
last_ip = ""
while True:
ip = requests.get("https://api.ipify.org").text
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)