Compare commits

...

8 commits

Author SHA1 Message Date
n
96ba32b610 Version 0.2.0 2025-02-01 16:48:45 -06:00
n
7d7bba643e Parse data 2025-02-01 16:48:31 -06:00
n
0306704d69 more error handling 2025-01-31 21:20:16 -06:00
n
87cc4999dc add error image 2025-01-31 21:19:30 -06:00
n
2b3409f9f3 fix (thank you paige) 2025-01-31 21:16:11 -06:00
n
87e8e051c0 ok 2025-01-31 21:15:43 -06:00
n
5392f00a49 0.2.0-dev 2025-01-31 21:13:05 -06:00
n
022064e227 Also fetch the data 2025-01-31 21:09:33 -06:00
3 changed files with 49 additions and 5 deletions

37
bot.py
View file

@ -2,7 +2,7 @@ import simplematrixbotlib as botLibrary
import json
import fetch
version = "0.1.5"
version = "0.2.0"
print("Imag/quotes bot version " + version)
print("Loading config…")
@ -73,16 +73,45 @@ async def make_choice(room, message):
id = match.args()
id = str(id[1])
quoteImage = fetch.fetchQuote(id)
quoteData = fetch.fetchQuoteData(id)
def formatData(data):
dataToFormat = data
created = str(data['created'])
description = str(data['desc'])
imageid = str(data['iid'])
ocr = str(data['ocr'])
score = str(data['score'])
return created, description, imageid, ocr, score
if debugMode == False:
pass
created, description, imageid, ocr, score = formatData(quoteData)
message1 = (f"""
Created: {created}
Description: {description}
Image ID: {imageid}
OCR (Tesseract): {ocr}
Rating: {score}
""")
else:
message = (f"""
created, description, imageid, ocr, score = formatData(quoteData)
message1 = (f"""
Created: {created}
Description: {description}
Image ID: {imageid}
OCR (Tesseract): {ocr}
Rating: {score}
""")
message2 = (f"""
Command recived (DEBUG).
(We're supposed to fetch quote number {id} now.)
""")
await bot.api.send_text_message(room.room_id, message)
if debugMode == True:
await bot.api.send_text_message(room.room_id, message2)
await bot.api.send_text_message(room.room_id, message1)
else:
await bot.api.send_text_message(room.room_id, message1)
imageMessage = (quoteImage)
await bot.api.send_image_message(room.room_id, imageMessage) # https://quotes.everypizza.im/image/178

BIN
error.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View file

@ -17,4 +17,19 @@ def fetchQuote(quoteId):
return filename
else:
print(f"An error occured while saving the file: {quote.status_code}")
return None
return "error.png"
def fetchQuoteData(quoteId):
processedId = str(config['imag']['server'] + "/api/image/" + str(quoteId))
print(processedId)
quoteData = requests.get(processedId)
code = 200
if quoteData.status_code == 200:
return quoteData.json()
# print(str(json.dumps(quoteData)))
print(quoteData.json())
else:
print(f"An error occured while saving the file: {quoteData.status_code}")
return "This file probably doesn't exist."
fetchQuoteData(178)