Created
May 2, 2021 18:07
-
-
Save KokoseiJ/69550251b72d3bde0fbea92c054b324a to your computer and use it in GitHub Desktop.
Check if URLs are alive, in specific interval
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
urldata file stores the interval(in seconds) between requests and urls to check.
it formats like this: