Compare commits

..

2 Commits

Author SHA1 Message Date
Lonami Exo ed81602fa3 Fix markdown 2019-05-11 20:09:41 +02:00
Lonami Exo f474f3cd59 Workaround duplicates from get_xkcds 2019-05-11 20:09:19 +02:00
1 changed files with 9 additions and 3 deletions

12
bot.py
View File

@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncio
from os import environ
from collections import namedtuple
from json import loads
@ -20,7 +21,7 @@ Xkcd = namedtuple('Xkcd', ['title', 'link', 'transcript', 'alt', 'number'])
URL_FMT_STR = "http://www.ohnorobot.com/index.php?Search=Search&comic=56&s={}"
# FIXME HTML parsemode + escaping
MSG_FMT_STR = "[{number}]({link}): *{title}*\n\n_{alt}_"
MSG_FMT_STR = "[{number}]({link}): **{title}**\n\n__{alt}__"
XKCD_JSON_FMT_STR = "https://xkcd.com/{}/info.0.json"
MAX_SEARCH_RESULTS = 10
@ -79,11 +80,16 @@ async def inlinequery(event):
"""Handle the inline query."""
# TODO show transcript in result but not message?
builder = event.builder
await event.answer([builder.article(
result = await asyncio.gather(*(builder.article(
title=xkcd.title,
url=xkcd.link,
text=MSG_FMT_STR.format(number=xkcd.number, link=xkcd.link, title=xkcd.title, alt=xkcd.alt)
) for xkcd in get_xkcds(event.text)])
) for xkcd in get_xkcds(event.text)))
# FIXME get_xkcds returns duplicates, which lead to the same result ID
# Build a dict by their ID to remove the duplicates
result = list({r.id: r for r in result}.values())
await event.answer(result)
def main():