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('不满足推送条件')
def gold_price_push_generator(price): ''' 首先获取所有需要推送数据,然后去价格表查最新的一条,将要推送的数据写入队列 ''' from login.login_funtion import User from push.push_function import PushList, PushData from model.gold_price_model import gold_price_push_option from peewee import DoesNotExist push_data_list = PushList(widget_id=WIDGET_ID_GOLD).push_list_get( is_need_2_push=True).push_list print('有%s条数据到达推送时间,需要检测是否满足推送条件' % str(len(push_data_list))) for push_data in push_data_list: user_id = push_data.user_id try: _ = gold_price_push_option.get( (gold_price_push_option.user_id == user_id) & (gold_price_push_option.is_valid == 1)) threshold_min = float(eval(_.push_threshold)[0]) threshold_max = float(eval(_.push_threshold)[1]) if price < threshold_min or price > threshold_max: content = 'Gold price is %s now!' % str(price) title = 'GoldPriceMonitor' if (push_data.add_to_push_queue(title, content)): print('已加入队列.') if (push_data.generate_next()): push_data.delete() else: print('不满足推送条件') except DoesNotExist: continue
def app_price_push_generator(): ''' 首先获取所有需要推送数据,然后去价格表查最新的一条,将要推送的数据写入队列 ''' app_push_data_list = PushList(widget_id=WIDGET_ID_APP).push_list_get( is_need_2_push=True).push_list print('有%s条数据到达推送时间,需要检测是否满足推送条件' % str(len(app_push_data_list))) for app_push_data in app_push_data_list: content = '' applist = app_get(app_push_data.user_id) for app in applist: current_price, update_time = app_price_get(app['id']) if float(current_price) <= float(app['expect_price']): content = content + '\n' + '[' + app[ 'name'] + ']' + ' is ¥' + str( current_price) + ' now !(' + update_time + ')' + '\n' if content != '': title = 'App Discount!' if (app_push_data.add_to_push_queue(title, content)): print('已加入队列.') if (app_push_data.generate_next()): app_push_data.delete() else: print('不满足推送条件')
def app_price_push_generator(): ''' 首先获取所有需要推送数据,然后去价格表查最新的一条,将要推送的数据写入队列 ''' app_push_data_list = PushList(widget_id=0).push_list_get( is_need_2_push=True).push_list print('有%s条数据等待推送...' % str(len(app_push_data_list))) for app_push_data in app_push_data_list: user_id = app_push_data.user_id content = '' applist = app_get(app_push_data.user_id) for app in applist: current_price, update_time = app_price_get(app['id']) if float(current_price) <= float(app['expect_price']): content = content + '\n' + '[' + app[ 'name'] + ']' + ' is ¥' + str( current_price) + ' now !(' + update_time + ')' + '\n' if content != '': if app_push_data.notify_method == 1: address = User(user_id=user_id).wechat_key elif app_push_data.notify_method == 2: address = User(user_id=user_id).email title = 'App Discount!' if (app_push_data.add_to_push_queue(title, address, content)): print('已加入队列.') if (app_push_data.generate_next()): app_push_data.delete()