Esempio n. 1
0
def resolve_vcode():
    data = request.data
    dct = json.loads(data)
    if isinstance(dct, dict):
        if dct['type'] == vcode.vcode_type:
            vcode.resolve_vcode(dct['vcode'])
            return get_success_response()
    return get_error_response('post a wrong data')
Esempio n. 2
0
def batch_wxid():
    data = request.data
    lst = json.loads(data)
    if isinstance(lst, list):
        sqlite_helper.batch_subscribe(lst)
        return get_success_response().format()
    else:
        return get_error_response(data + 'is not a list').format()
Esempio n. 3
0
def get_log(line):
    try:
        line = int(line)
    except ValueError:
        return get_error_response('line must be a int number: %s' % line).format()
    if not line:
        line = 0
    l = download_queue.get_log_from(int(line))
    return ResponseBody(log=l).format()
Esempio n. 4
0
def save_page():
    subscribes = sqlite_helper.get_wxid_list()
    print(subscribes)
    try:
        info_list = list()
        for s in subscribes:
            print("processing wxid=%s" % s['name'])
            all_articles = sogou_api.get_articles_by_id(s['name'])
            for a in all_articles:
                info_list.append(a)
            download_queue.resolve(info_list)
        return get_success_response().format()
    except Exception as e:
        return get_error_response(e.message).format()
Esempio n. 5
0
def page_not_found(e):
    return get_error_response('Not found', should_print=False).format(), 404
Esempio n. 6
0
def get_vcode_img():
    if vcode.vcode_type == vcode.VCODE_FROM_ARTICLE_LIST:
        return app.send_static_file(config.cache_path + 'article_list_vcode.png')
    else:
        return get_error_response('no vcode image found').format()
Esempio n. 7
0
def get_articles_by_date_created(date):
    if not common.valid_date_string(date):
        return get_error_response('%s is not a date' % date).format()
    articles = sqlite_helper.get_articles_by_date_created(date)
    return ResponseBody(articles=articles).format()
Esempio n. 8
0
def start():
    return get_success_response().format() if download_queue.start() else get_error_response('spider is running').format()
Esempio n. 9
0
def add_wxid(wxid):
    try:
        sqlite_helper.subscribe(wxid)
        return get_success_response().format()
    except Exception as e:
        return get_error_response(e.message).format()