From f474f3cd59e0bae2c741dff2090e23c9f0443e1b Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 11 May 2019 20:09:19 +0200 Subject: [PATCH] Workaround duplicates from get_xkcds --- bot.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index be17666..85e79d0 100644 --- a/bot.py +++ b/bot.py @@ -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 @@ -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():