deleting redundant code
This commit is contained in:
parent
d628e14742
commit
141bfc2a7e
Binary file not shown.
Binary file not shown.
|
@ -1,31 +0,0 @@
|
|||
import os
|
||||
import requests
|
||||
import logging
|
||||
|
||||
def getCat():
|
||||
endpoint = "https://api.thecatapi.com/v1/images/search"
|
||||
headers = {"x-api-key": "live_DG62StQrrv2Fm1Jws2Xm2kxzpyQ0rIiY90cCdbLxGoXc7rmljlUFQ1APwxu925Dr"}
|
||||
|
||||
logger = logging.getLogger("catAPI")
|
||||
|
||||
try:
|
||||
response = requests.get(endpoint, headers=headers)
|
||||
response.raise_for_status()
|
||||
#errors 400 500
|
||||
except requests.exceptions.HTTPError as err:
|
||||
logger.error("HTTP Error: %s", err)
|
||||
return
|
||||
#timeouts
|
||||
except requests.exceptions.RequestException as err:
|
||||
logger.error("Error: %s", err)
|
||||
return
|
||||
|
||||
# Get the image URL and save the image
|
||||
data = response.json()
|
||||
url = data[0]['url']
|
||||
try:
|
||||
response = requests.get(url)
|
||||
open("img/cat.jpg", "wb").write(response.content)
|
||||
print("Image saved to img/cat.jpg")
|
||||
except requests.exceptions.RequestException as err:
|
||||
logger.error("Error: %s", err)
|
Binary file not shown.
Before Width: | Height: | Size: 342 KiB After Width: | Height: | Size: 58 KiB |
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<note>
|
||||
<to>inny</to>
|
||||
<from>plik</from>
|
||||
<heading>Reminder</heading>
|
||||
<body>Don't forget me this weekend!</body>
|
||||
</note>
|
Loading…
Reference in New Issue