Skip to content

Instantly share code, notes, and snippets.

@zipacna
Last active July 9, 2021 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zipacna/ab18e47955676002311fc3676b7ff873 to your computer and use it in GitHub Desktop.
Save zipacna/ab18e47955676002311fc3676b7ff873 to your computer and use it in GitHub Desktop.
GET all Images from http.cat responding to the http status codes
"""
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