Esempio n. 1
0
def handle_callback_query(query):
    logger.info(query.data)

    # query.answer()
    chat_id = query.message.chat.id

    arr = query.data.split(":")
    query_type, query_value = arr[0], arr[1]

    if query_type == 'download_bilibili_cover':
        # 提取 B 站视频的封面图片
        pic_url = services.get_bilibili_cover_img(query_value)
        bot.send_photo(chat_id=chat_id, photo=pic_url)

    elif query_type == 'download_bilibili_video':
        query.edit_message_text(text="小关正在加速为您下载视频,稍后会将下载链接呈上!!!")

        title = services.download_bilibili_video(query_value)
        logger.debug('Download {}'.format(title))

        download_url = 'https://telegram.pushy.site/download/{}.flv'.format(
            title)
        bot.send_message(chat_id=chat_id,
                         text='下载链接为: {}'.format(download_url))

    elif query_type == 'download_zhihu_video':
        download_url = services.get_zhihu_video_download_url(
            'https://www.zhihu.com/video/{}'.format(query_value))
        query.edit_message_text(text=download_url)
Esempio n. 2
0
async def fetch_price_task():
    while True:
        logger.debug('Checking current price...')
        price = await get_current_price()
        message = 'Current  bitcoin price is {:.2f}$'.format(price)
        if config.NOTIFICATIONS_ENABLED:
            logger.debug('Sending message to a channel...')
            await send_message(message)
        await asyncio.sleep(config.POLL_PRICE_PERIOD)
Esempio n. 3
0
def check_update(key, first_page_func):
    latest_item = first_page_func()[0]
    title, url = latest_item['title'], latest_item['url']

    if not redis.hexists(key, title):
        content = '您订阅的博客发布了新的文章《{}》,原文链接:\n{}'.format(title, url)
        logger.debug(content)
        bot.send_message(chat_id=1040935564, text=content)
        redis.hset(key, title, url)
    else:
        logger.debug('没更新')
Esempio n. 4
0
    def generate_results_table(self):
        logger.info("Entered the method creating the results table")
        lengths = []
        output = {}
        for material in self.material:
            for beam in material.beams:
                if beam.length not in lengths:
                    lengths.append(beam.length)

        lengths.sort()
        logger.debug(lengths)

        for material in self.material:
            output.setdefault(material.size, [])

        logger.debug(output)

        answer = {}
        for material in self.material:
            answer.setdefault(material.size, {})
            for length in lengths:
                answer[material.size][length] = 0

            for beam in material.beams:
                if beam.length in answer[material.size].keys():
                    answer[material.size][beam.length] += beam.qty

            logger.debug(answer[material.size])
        logger.debug(answer)

        output = {}

        for key in answer.keys():
            current = answer[key]
            output[key] = []

            for length in lengths:
                qty = ""
                warning = ""
                if current[length] > 0:
                    qty = current[length]
                    warning = "warning"

                output[key].append((qty, warning, length))

        logger.debug(output)

        self.result_table = output
        logger.info("Exiting the method creating the results table")
Esempio n. 5
0
def get_buy_suggestion(cur_price, lowest_price, history_prices):
    # 比较是不是历史最低
    lower_than_history = True
    for each in history_prices:
        if cur_price >= each:
            lower_than_history = False

    if lower_than_history:
        result = '发现当前为历史最低价格,非常建议购买!!!'
    else:
        if cur_price > lowest_price:
            result = '现在不是最佳时刻!最低价格为:{}'.format(lowest_price)
        else:
            result = '现在是最佳时刻'

    logger.debug('购买意见为: {}'.format(result))
    return result
Esempio n. 6
0
async def check_transactions_task():
    while True:
        logger.debug('Checking transactions to close...')
        await check_transactions()

        await asyncio.sleep(config.CHECK_TRANSACTIONS_PERIOD)
Esempio n. 7
0
File: app.py Progetto: bmwant/escot
async def close_tasks(app):
    for task in app.get('tasks', []):
        logger.debug('Cancelling task %s...', task._coro.__name__)
        task.cancel()
Esempio n. 8
0
def query_price(link):
    html = http_get('http://p.zwjhl.com/price.aspx?url={}'.format(link)).text
    if html.find('该商品暂未收录') != -1:
        return None, None

    element = etree.HTML(html)

    # 该商品的最低价格
    lowest_price = float(
        utils.clean_text(
            element.xpath('//div[@class="bigwidth"]/span[1]/font[2]/text()')
            [0]))
    # 该商品最低价格的日期
    lowest_price_date = element.xpath(
        '//div[@class="bigwidth"]/span[1]/font[3]/text()')[0][1:-1]
    # 该商品当前价格
    cur_price = float(
        utils.clean_text(
            element.xpath('//div[@class="bigwidth"]/span[1]/text()')
            [-1]).replace('\xa0当前价:', ''))

    logger.debug('最低价格: {};最低价格日期: {};当前价格:{}'.format(lowest_price,
                                                      lowest_price_date,
                                                      cur_price))

    temp = re.findall("<script type='text/javascript'>(.*?)</script>", html,
                      re.S)[0]
    timestamp_list = []  # x 轴数据
    price_list = []  # y 轴数据

    # 填充 X 轴(时间线) 和 Y 轴(价格变化) 的数据
    result = re.findall("\[(.*?)\]", temp, re.S)
    for each in result:
        arr = each.split(",")
        timestamp_list.append(
            datetime.fromtimestamp(int(arr[0]) / 1000).strftime('%Y-%m-%d'))
        price_list.append(float(arr[1]))

    temp_id = str(uuid.uuid4())

    # 开始画图,并通过 Selenium 截图保存数据图
    plotly.offline.plot(
        {
            'data': [{
                'x': timestamp_list,
                'y': price_list
            }],
            'layout': {
                'title': 'Price trend graph',
                'font': dict(size=12)
            }
        },
        filename='temp/{}.html'.format(temp_id),
        image='svg',
        auto_open=False,
        image_width=1000,
        image_height=500)
    # 获取当前工作路径
    path = '{}/temp/{}.html'.format(Path.cwd(), temp_id)
    logger.debug('save html to: {}'.format(path))

    suggestion = get_buy_suggestion(cur_price, lowest_price, price_list)
    return utils.save_html_screenshot(temp_id,
                                      path), '小关觉得{}'.format(suggestion)