Last active
July 9, 2021 14:02
-
-
Save zipacna/ab18e47955676002311fc3676b7ff873 to your computer and use it in GitHub Desktop.
GET all Images from http.cat responding to the http status codes
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
""" | |
GET all Images from http.cat responding to the http status codes | |
Author: Jean Mattes | |
Author-URI: https://risingcode.net | |
Source: https://http.cat | |
""" | |
from http.client import responses | |
from urllib import error, request | |
from os.path import isfile | |
def download(code): | |
try: | |
img_url = 'https://http.cat/{}.jpg'.format(code) | |
request.urlretrieve(img_url, '{}.jpg'.format(code)) | |
except error.URLError: | |
return False | |
return True | |
def driver(): | |
codes = [r.value for r in responses] | |
# Append "unoffical" codes with images present. | |
for a in [418, 420, 425, 444, 450, 451, 499, 509, 599]: | |
codes.append(a) | |
# Remove "offical" codes with NO image present. | |
for r in [205, 208, 226, 428, 505]: | |
codes.remove(r) | |
for c in codes: | |
invalidate = False | |
if invalidate or not isfile('{}.jpg'.format(c)): | |
download(c) | |
if __name__ == '__main__': | |
driver() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment