Compare commits
8 commits
d83463d27a
...
96ba32b610
Author | SHA1 | Date | |
---|---|---|---|
96ba32b610 | |||
7d7bba643e | |||
0306704d69 | |||
87cc4999dc | |||
2b3409f9f3 | |||
87e8e051c0 | |||
5392f00a49 | |||
022064e227 |
3 changed files with 49 additions and 5 deletions
37
bot.py
37
bot.py
|
@ -2,7 +2,7 @@ import simplematrixbotlib as botLibrary
|
||||||
import json
|
import json
|
||||||
import fetch
|
import fetch
|
||||||
|
|
||||||
version = "0.1.5"
|
version = "0.2.0"
|
||||||
|
|
||||||
print("Imag/quotes bot version " + version)
|
print("Imag/quotes bot version " + version)
|
||||||
print("Loading config…")
|
print("Loading config…")
|
||||||
|
@ -73,16 +73,45 @@ async def make_choice(room, message):
|
||||||
id = match.args()
|
id = match.args()
|
||||||
id = str(id[1])
|
id = str(id[1])
|
||||||
quoteImage = fetch.fetchQuote(id)
|
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:
|
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:
|
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).
|
Command recived (DEBUG).
|
||||||
(We're supposed to fetch quote number {id} now.)
|
(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)
|
imageMessage = (quoteImage)
|
||||||
await bot.api.send_image_message(room.room_id, imageMessage) # https://quotes.everypizza.im/image/178
|
await bot.api.send_image_message(room.room_id, imageMessage) # https://quotes.everypizza.im/image/178
|
||||||
|
|
||||||
|
|
BIN
error.png
Normal file
BIN
error.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
17
fetch.py
17
fetch.py
|
@ -17,4 +17,19 @@ def fetchQuote(quoteId):
|
||||||
return filename
|
return filename
|
||||||
else:
|
else:
|
||||||
print(f"An error occured while saving the file: {quote.status_code}")
|
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)
|
||||||
|
|
Loading…
Add table
Reference in a new issue