Compare commits
4 commits
186563a560
...
212d97b42e
Author | SHA1 | Date | |
---|---|---|---|
212d97b42e | |||
f91c210211 | |||
af0acc6e6a | |||
d852b660c5 |
3 changed files with 17 additions and 9 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -165,4 +165,5 @@ cython_debug/
|
|||
*config.json
|
||||
*.kate-swp
|
||||
session.txt
|
||||
*.jpg
|
||||
|
||||
|
|
6
bot.py
6
bot.py
|
@ -40,13 +40,15 @@ async def make_choice(room, message):
|
|||
else:
|
||||
id = match.args()
|
||||
id = str(id[1])
|
||||
quoteLink = fetch.fetchQuote(id)
|
||||
quoteImage = fetch.fetchQuote(id)
|
||||
message = (f"""
|
||||
Command recived (DEBUG).
|
||||
(We're supposed to fetch quote number {id} now, from {quoteLink}.)
|
||||
(We're supposed to fetch quote number {id} now.)
|
||||
""")
|
||||
|
||||
await bot.api.send_text_message(room.room_id, message)
|
||||
imageMessage = (quoteImage)
|
||||
await bot.api.send_image_message(room.room_id, imageMessage) # https://quotes.everypizza.im/image/178
|
||||
|
||||
@bot.listener.on_message_event
|
||||
async def help_message(room, message):
|
||||
|
|
19
fetch.py
19
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
|
||||
else:
|
||||
print(f"An error occured while saving the file: {quote.status_code}")
|
||||
return None
|
||||
|
||||
fetchQuote(34)
|
||||
|
|
Loading…
Add table
Reference in a new issue