make fetch actually work
This commit is contained in:
parent
186563a560
commit
d852b660c5
2 changed files with 14 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -165,4 +165,5 @@ cython_debug/
|
||||||
*config.json
|
*config.json
|
||||||
*.kate-swp
|
*.kate-swp
|
||||||
session.txt
|
session.txt
|
||||||
|
*.jpg
|
||||||
|
|
||||||
|
|
21
fetch.py
21
fetch.py
|
@ -5,13 +5,18 @@ with open('config.json', 'r') as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
|
|
||||||
def fetchQuote(quoteId):
|
def fetchQuote(quoteId):
|
||||||
processedId = str(config['imag']['server'] + "/image/" + quoteId)
|
processedId = str(config['imag']['server'] + "/image/" + str(quoteId))
|
||||||
# quote = requests.get(processedId)
|
print(processedId)
|
||||||
#temporary
|
quote = requests.get(processedId)
|
||||||
|
filename = str(quoteId) + ".jpg"
|
||||||
code = 200
|
code = 200
|
||||||
if code == 200:
|
if quote.status_code == 200:
|
||||||
# return quote.content
|
with open(filename, "wb") as f:
|
||||||
return processedId
|
f.write(quote.content)
|
||||||
print(processedId)
|
print(f"File saved as {filename}")
|
||||||
|
return filename # Return the filename to indicate success
|
||||||
else:
|
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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue