instagram.py 文件源码

python
阅读 37 收藏 0 点赞 0 评论 0

项目:Siarobo 作者: siyanew 项目源码 文件源码
def inline(message, matches, chat_id, step):
    query_id, from_id, query = telepot.glance(message, flavor='inline_query')
    response = requests.get(query)
    soup = BeautifulSoup(response.text, "html.parser")
    image = soup.find("meta", {"property": "og:image"})
    video = soup.find("meta", {"property": "og:video"})
    if video:
        width = soup.find("meta", {"property": "og:video:width"})
        height = soup.find("meta", {"property": "og:video:height"})
        return [InlineQueryResultVideo(
            id=str(uuid.uuid4()), description='Instagram Video', title="Instagram Video", mime_type="video/mp4",
            thumb_url=image['content'], video_url=video['content'], video_width=int(width['content']),
            video_height=int(height['content']))]
    elif image:
        return [InlineQueryResultPhoto(
            id=str(uuid.uuid4()), title="Instagram Photo",
            photo_url=image['content'], photo_width=300, photo_height=300,
            thumb_url=image['content'])]
    else:
        return [InlineQueryResultArticle(
            id=str(uuid.uuid4()), title='Error', description="Not Found",
            input_message_content=InputTextMessageContent(message_text="Error\nNot Found", parse_mode="Markdown"),
            thumb_url="http://siyanew.com/bots/custom.jpg")]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号