Compare commits

..

No commits in common. "ed81602fa3ad92dc88f05841b078177d3422be10" and "700593f889109e668fad151813ef41679be8db55" have entirely different histories.

1 changed files with 3 additions and 9 deletions

12
bot.py
View File

@ -1,6 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import asyncio
from os import environ from os import environ
from collections import namedtuple from collections import namedtuple
from json import loads from json import loads
@ -21,7 +20,7 @@ Xkcd = namedtuple('Xkcd', ['title', 'link', 'transcript', 'alt', 'number'])
URL_FMT_STR = "http://www.ohnorobot.com/index.php?Search=Search&comic=56&s={}" URL_FMT_STR = "http://www.ohnorobot.com/index.php?Search=Search&comic=56&s={}"
# FIXME HTML parsemode + escaping # 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" XKCD_JSON_FMT_STR = "https://xkcd.com/{}/info.0.json"
MAX_SEARCH_RESULTS = 10 MAX_SEARCH_RESULTS = 10
@ -80,16 +79,11 @@ async def inlinequery(event):
"""Handle the inline query.""" """Handle the inline query."""
# TODO show transcript in result but not message? # TODO show transcript in result but not message?
builder = event.builder builder = event.builder
result = await asyncio.gather(*(builder.article( await event.answer([builder.article(
title=xkcd.title, title=xkcd.title,
url=xkcd.link, url=xkcd.link,
text=MSG_FMT_STR.format(number=xkcd.number, link=xkcd.link, title=xkcd.title, alt=xkcd.alt) 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(): def main():