From d852b660c5b05b86f2b67349916fe58ad6bf50ee Mon Sep 17 00:00:00 2001 From: n Date: Fri, 31 Jan 2025 20:12:41 -0600 Subject: [PATCH] make fetch actually work --- .gitignore | 1 + fetch.py | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 628494a..1cc7fd6 100644 --- a/.gitignore +++ b/.gitignore @@ -165,4 +165,5 @@ cython_debug/ *config.json *.kate-swp session.txt +*.jpg diff --git a/fetch.py b/fetch.py index 8574548..0866dbf 100644 --- a/fetch.py +++ b/fetch.py @@ -5,13 +5,18 @@ with open('config.json', 'r') as f: config = json.load(f) def fetchQuote(quoteId): - processedId = str(config['imag']['server'] + "/image/" + quoteId) - # quote = requests.get(processedId) - #temporary + processedId = str(config['imag']['server'] + "/image/" + str(quoteId)) + print(processedId) + quote = requests.get(processedId) + filename = str(quoteId) + ".jpg" code = 200 - if code == 200: - # return quote.content - return processedId - print(processedId) + if quote.status_code == 200: + with open(filename, "wb") as f: + f.write(quote.content) + print(f"File saved as {filename}") + return filename # Return the filename to indicate success else: - return None + print(f"An error occured while saving the file: {quote.status_code}") # Corrected status code variable + return None # Return None to indicate failure + +fetchQuote(34)