quotes-bot-python/fetch.py

21 lines
588 B
Python
Raw Permalink Normal View History

2025-01-31 18:39:10 -06:00
import requests
2025-01-31 19:03:35 -06:00
import json
with open('config.json', 'r') as f:
config = json.load(f)
2025-01-31 18:39:10 -06:00
2025-01-31 18:58:23 -06:00
def fetchQuote(quoteId):
2025-01-31 20:12:41 -06:00
processedId = str(config['imag']['server'] + "/image/" + str(quoteId))
print(processedId)
quote = requests.get(processedId)
filename = str(quoteId) + ".jpg"
code = 200
2025-01-31 20:12:41 -06:00
if quote.status_code == 200:
with open(filename, "wb") as f:
f.write(quote.content)
print(f"File saved as {filename}")
2025-01-31 20:19:14 -06:00
return filename
2025-01-31 18:58:23 -06:00
else:
2025-01-31 20:19:14 -06:00
print(f"An error occured while saving the file: {quote.status_code}")
return None