def stock_push_generator():
    '''
        首先获取所有需要推送数据,然后去价格表查最新的一条,将要推送的数据写入队列
    '''
    WIDGET_ID_STOCK = widget.get(widget.name == 'stock').id
    stock_push_data_list = PushList(widget_id=WIDGET_ID_STOCK).push_list_get(is_need_2_push=True).push_list
    print('有%s条数据到达推送时间,需要检测是否满足推送条件' % str(len(stock_push_data_list)))
    for stock_push_data in stock_push_data_list:

        content = ''
        stock_list = stock_belong.select().where((stock_belong.user_id == stock_push_data.user_id) & (stock_belong.is_valid == 1) & (stock_belong.push == 1)).dicts()
        for stock in stock_list:
            query = stock_price.select().where(stock_price.stock_id == stock['stock_id']).order_by(-stock_price.id).limit(1).dicts()
            current_price, update_time = query[0]['price'], query[0]['update_time'].strftime("%m-%d %H:%M")
            threshold_min = float(eval(stock['push_threshold'])[0])
            threshold_max = float(eval(stock['push_threshold'])[1])
            if (float(current_price) < threshold_min) or (float(current_price) > threshold_max):
                content = content + '\n' + '[' + stock_table.get_by_id(stock['stock_id']).name + ']' + ' is ' + str(current_price) + ' now !(' + update_time + ')' + '\n'
        if content != '':
            title = '%s 的价格超过阈值!' % stock_table.get_by_id(stock['stock_id']).name
            if (stock_push_data.add_to_push_queue(title, content)):
                print('已加入队列.')
                if (stock_push_data.generate_next()):
                    stock_push_data.delete()
        else:
            print('不满足推送条件')
Пример #2
0
sys.path.append('../')
sys.path.append('../../')
from bs4 import BeautifulSoup

from model.push_model import push
from model.widget_model import widget
from model.app_model import app as app_table
from model.app_model import app_price as app_price_table

from login.login_funtion import User
from push.push_function import PushList, PushData

from app_function import app_get, app_price_get

count = 0
WIDGET_ID_APP = widget.get(widget.name == 'app').id


def get_app_price(app_id, app_url):
    '''
        爬取数据:接收app的Url后缀,返回app的名字和价格。
    '''
    global count
    count += 1

    response = requests.get(app_url)
    soup = BeautifulSoup(response.text, 'lxml')

    app_name = soup.find(class_='product-header__title app-header__title')

    app_price = soup.find(
import datetime
import requests
from bs4 import BeautifulSoup

try:
    from ..model.gold_price_model import gold_price
    from ..model.widget_model import widget
except:
    import sys
    sys.path.append('../')
    sys.path.append('../../')
    from model.gold_price_model import gold_price
    from model.widget_model import widget

count = 0
WIDGET_ID_GOLD = widget.get(widget.name == 'gold').id


def get_gold_price():
    '''
    返回当前黄金价格
    '''
    for x in range(5):
        response = requests.get("http://www.dyhjw.com/hjtd")
        soup = BeautifulSoup(response.text, 'lxml')

        divs = soup.find(class_='nom last green')
        if not divs:
            divs = soup.find(class_='nom last red')
            if not divs:
                divs = soup.find(class_='nom last ')