33 lines
955 B
Python
33 lines
955 B
Python
import pydle
|
|
import requests
|
|
import random
|
|
|
|
host = "https://collectionapi.metmuseum.org/public/collection/v1/"
|
|
|
|
# get the list of artwork
|
|
r = requests.get(host + 'objects')
|
|
objects = r.json()['objectIDs']
|
|
|
|
def getArt():
|
|
while True:
|
|
r = requests.get(host + 'objects/' + str(random.choice(objects)))
|
|
j = r.json()
|
|
if j['primaryImage']:
|
|
return j
|
|
|
|
# Simple echo bot.
|
|
class RadioBot(pydle.Client):
|
|
async def on_connect(self):
|
|
await self.join('#dailybot')
|
|
await self.join('#dailybuild')
|
|
|
|
async def on_message(self, target, source, message):
|
|
# don't respond to our own messages, as this leads to a positive feedback loop
|
|
if source != self.nickname:
|
|
if message.startswith(".art"):
|
|
art = getArt()
|
|
await self.message(target, '"' + art['title'] + '" ' + art['objectDate'] + '" ' + art['primaryImage'])
|
|
|
|
client = RadioBot('ArtBot', realname='ArtBot')
|
|
client.run('irc.rizon.net', tls=True, tls_verify=True)
|