Skip to content

Instantly share code, notes, and snippets.

@KokoseiJ
Created May 2, 2021 18:07
Show Gist options
  • Save KokoseiJ/69550251b72d3bde0fbea92c054b324a to your computer and use it in GitHub Desktop.
Save KokoseiJ/69550251b72d3bde0fbea92c054b324a to your computer and use it in GitHub Desktop.
Check if URLs are alive, in specific interval
import time
import requests
with open("urldata", "r") as f:
data = f.read().split("\n")
interval = int(data[0])
url_list = [x for x in data[1:] if x]
maxlen = max(map(len, url_list))
count = 1
print(f"Interval: {interval}")
print("URLs on the list:")
print("\n".join(url_list))
while True:
print(f"\nConnection {count}")
for url in url_list:
r = requests.get(url, headers={"User-Agent": "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0"})
if r.status_code == 200:
print(f"{url} IS NOW ALIVE!")
exit()
else:
print(f"{url}{' ' * (maxlen - len(url))} : {r.status_code}")
time.sleep(interval)
count += 1
@KokoseiJ
Copy link
Author

KokoseiJ commented May 2, 2021

urldata file stores the interval(in seconds) between requests and urls to check.
it formats like this:

60
https://url-to-check.com/
https://another-url-to-check.org/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment