Ejemplo n.º 1
0
def app_get(user_id=0):
    '''
        获取用户id下有效的app,user_id不传则获取全部

        args:user_id(Int)(default:0)
        returns:app_list(List)
    '''
    if user_id == 0:
        app_table_query = app_table.select().where(
            app_table.is_valid == 1).dicts()
    else:
        app_table_query = app_table.select().where(
            (app_table.user_id == user_id)
            & (app_table.is_valid == 1)).order_by(app_table.order).dicts()
    result = [{
        'id': row['id'],
        'name': row['name'],
        'url': row['url'],
        'expect_price': row['expect_price'],
        'update_time': row['update_time']
    } for row in app_table_query]
    return result
Ejemplo n.º 2
0
            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('不满足推送条件')


# 单线程爬取数据
# app_table_query = app_table.select().where(app_table.is_valid == 1).dicts()
# for single_app_table_query in app_table_query:
#     app_name, app_price = get_app_price(single_app_table_query['id'], single_app_table_query['url'])

# 多线程爬取数据
app_table_query = app_table.select().where(app_table.is_valid == 1).dicts()
import threading
threads = []
for single_app_table_query in app_table_query:
    threads.append(
        threading.Thread(target=get_app_price,
                         args=(
                             single_app_table_query['id'],
                             single_app_table_query['url'],
                         )))
for t in threads:
    t.start()
for t in threads:
    t.join()

#加入推送队列