Beispiel #1
0
def choose_link(call):
    bot.send_chat_action(call.message.chat.id, 'typing')
    # call.data is url, http://www.rrys2020.com/resource/36588
    resource_url = re.findall(r"choose(\S*)", call.data)[0]
    markup = types.InlineKeyboardMarkup()

    if OFFLINE:
        worker_page = offline_link(resource_url)
        btn1 = types.InlineKeyboardButton("打开网页", url=worker_page)
        markup.add(btn1)
        bot.send_message(call.message.chat.id, "离线模式,点击按钮打开网页获取结果", reply_markup=markup)
        return

    link = yyets_get_from_cache(resource_url)
    if not link:
        link = get_detail_page(resource_url)
        save_to_cache(resource_url, link)

    btn1 = types.InlineKeyboardButton("分享页面", callback_data="share%s" % resource_url)
    btn2 = types.InlineKeyboardButton("我全都要", callback_data="all%s" % resource_url)
    markup.add(btn1, btn2)
    text = "想要分享页面,还是我全都要?\n\n" \
           "名词解释:“分享页面”会返回给你一个网站,从那里可以看到全部的下载链接。\n" \
           "“我全都要”会给你发送一个txt文件,文件里包含全部下载连接\n"
    bot.send_message(call.message.chat.id, text, reply_markup=markup)
Beispiel #2
0
def yyets_get_from_cache(url: str) -> dict:
    logging.info("Reading data from cache %s", url)
    from html_request import get_detail_page

    data = r.get(url)
    if data:
        logging.info("Cache hit")
        return json.loads(data)
    else:
        logging.info("Cache miss")
        save_to_cache(url, get_detail_page(url))
        return yyets_get_from_cache(url)
Beispiel #3
0
def choose_link(call):
    bot.send_chat_action(call.message.chat.id, 'typing')
    resource_url = call.data
    link = get_detail_page(resource_url)
    upsert(call.id, link)
    markup = types.InlineKeyboardMarkup()
    btn1 = types.InlineKeyboardButton("分享页面",
                                      callback_data="share%s" % call.id)
    btn2 = types.InlineKeyboardButton("继续点按钮",
                                      callback_data="select%s" % call.id)
    markup.add(btn1, btn2)
    bot.send_message(call.message.chat.id,
                     "想要分享页面,还是继续点击按钮",
                     reply_markup=markup)