示例#1
0
def uclite_list_cmd_view(request, cmd):
    ctx = fetch_context(request)
    json_data = dict()
    handle_request(request, ctx, json_data)
    json_data.update(
        run_html(Filters.list_node_filter, ctx["rsp_html"], ctx["rsp_url"]))

    max_index = int(ctx["req_params"].get("index", "0"))
    json_data["list_chncat"] = ctx["req_url_params"].get("chncat", "0")
    json_data["list_key"] = ctx["req_url"][ctx["req_url"].find('/list/') +
                                           6:ctx["req_url"].find('?')]
    json_data["list_id"] = request.GET.get("id", "-1")
    has_index = json_data["list_key"] == "topics"
    if 'items' in json_data:
        for i, item in enumerate(json_data['items']):
            json_data['items'][i]['index'] = int(json_data['items'][i].get(
                'index', '0')) + max_index + 1
        json_data['max_index'] = max_index + len(json_data['items'])

    if has_index:
        json_data["first_pos"] = ""
        if cmd == "prepend":
            cmd = "replace"

    ctx["json_data"] = json_data
    ctx["xml_data"] = templates.list_node_template.render(
        ctx["json_data"]).encode("utf-8")
    xml_node = etree.XML(ctx["xml_data"])
    ctx["pb_data"] = xml2pb(xml_node, cmd, request.GET.get("id", "N/A"), "Ok")
    return gen_response(request, ctx)
示例#2
0
def facebook_stories_more(request):

    ctx = fetch_context(request)
    json_data = dict()
    handle_fb_request(request, ctx, json_data, fetch_html=False)
    node_id = request.GET.get("id", "N/A")
    pos_data = list()
    for key, value in request.POST.iteritems():
        pos_data.append("%s=%s" % (key, value))
        json_data[key] = value
    ctx["fetch_html_begin_time"] = time.time()

    post_data = request.body
    rsp_url, rsp_html, rsp_cookie = net_client.fb_post_data(
        ctx["req_url"], post_data, cookies=ctx["req_cookie"])
    open("more.html", "w+").write(rsp_html.encode("utf-8"))
    section_html = handle_facebook_json("replace", rsp_html)
    resp_script = handle_facebook_json("script", rsp_html)
    str_json = get_handler_json1(resp_script)
    aftercursor = get_aftercursor(str_json)
    ctx["rsp_url"] = rsp_url
    ctx["rsp_html"] = section_html
    html_ret = run_html(FbFilters.time_line_more_filter, section_html,
                        ctx["rsp_url"])
    ctx["fetch_html_end_time"] = time.time()
    ctx["rsp_cookie"] = ctx["req_cookie"]
    json_data.update(html_ret)
    json_data["aftercursor"] = aftercursor
    ctx["json_data"] = json_data
    ctx["xml_data"] = FbTemplates.time_line_more.render(json_data).encode(
        "utf-8")
    xml_node = etree.XML(ctx["xml_data"])
    ctx["pb_data"] = xml2pb(xml_node, "append", "page_list", "Ok")

    return gen_response(request, ctx)
示例#3
0
def uclite_feedback_view(request, page_type):
    ctx = fetch_context(request)
    json_data = dict()
    handle_request(request, ctx, json_data)
    json_data["ref_url"] = request.GET.get('ref', "")
    if page_type == 'index':
        json_data.update(
            run_html(Filters.index_feedback_filter, ctx["rsp_html"],
                     ctx["rsp_url"]))
        ctx["xml_data"] = templates.index_feedback_template.render(
            json_data).encode("utf-8")
    else:
        json_data.update(
            run_html(Filters.detail_feedback_filter, ctx["rsp_html"],
                     ctx["rsp_url"]))
        ctx["xml_data"] = templates.detail_feedback_template.render(
            json_data).encode("utf-8")

    ctx["json_data"] = json_data
    xml_node = etree.XML(ctx["xml_data"])
    ctx["pb_data"] = xml2pb(xml_node, "replace", request.GET.get("id", "0"),
                            "Ok")
    return gen_response(request, ctx)
示例#4
0
def uclite_content_append_view(request):
    ctx = fetch_context(request)
    json_data = dict()
    handle_request(request, ctx, json_data)
    json_data.update(
        run_html(Filters.content_page_more_text_filter, ctx["rsp_html"],
                 ctx["rsp_url"]))

    ctx["json_data"] = json_data
    ctx["xml_data"] = templates.content_page_more_template.render(
        ctx["json_data"]).encode("utf-8")
    xml_node = etree.XML(ctx["xml_data"])
    ctx["pb_data"] = xml2pb(xml_node, "append", "content_read_more", "Ok")
    return gen_response(request, ctx)
示例#5
0
def uclite_content_view(request):
    ctx = fetch_context(request)
    json_data = dict()
    handle_request(request, ctx, json_data, cache_enable=True)
    json_data.update(
        run_html(Filters.content_page_filter, ctx["rsp_html"], ctx["rsp_url"]))
    json_data["list_id"] = "hot_list"
    ctx["json_data"] = json_data
    ctx["xml_data"] = templates.content_page_template.render(
        ctx["json_data"]).encode("utf-8")
    xml_node = etree.XML(ctx["xml_data"])
    ctx["pb_data"] = xml2pb(xml_node, "replace", "0", "Ok")
    rsp = gen_response(request, ctx)
    rsp["Cache-Control"] = "max-age=%d" % content_page_cache_seconds
    return rsp
示例#6
0
def facebook_test_stories(request):
    ctx = fetch_context(request)
    json_data = dict()
    handle_fb_request(request, ctx, json_data, False)
    ctx["rsp_cookie"] = ctx["req_cookie"]
    all_text = open("./facebookm.html", "r").read().decode("utf-8")
    html_ret = run_html(FbFilters.time_line_filter, all_text, "")

    json_data.update(html_ret)
    ctx["json_data"] = json_data
    ctx["xml_data"] = FbTemplates.time_line_template.render(json_data).encode(
        "utf-8")
    open("xml_data_test.xml", "w+").write(ctx["xml_data"])
    xml_node = etree.XML(ctx["xml_data"])

    ctx["pb_data"] = xml2pb(xml_node, "replace", "0", "Ok")
    return gen_response(request, ctx)
示例#7
0
def uclite_content_list_cmd_view(request):
    ctx = fetch_context(request)
    json_data = dict()
    handle_request(request, ctx, json_data)
    json_data.update(
        run_html(Filters.content_page_hot_list_filter, ctx["rsp_html"],
                 ctx["rsp_url"]))

    json_data["list_chncat"] = ctx["req_url_params"].get(
        "chncat", 'hotnews_indonesian')
    json_data["list_key"] = ctx["req_url"][ctx["req_url"].find('/list/') +
                                           6:ctx["req_url"].find('?')]
    json_data["list_id"] = request.GET.get("id", "-1")
    first_page = ctx["req_url_params"].get("firstPage", "")
    page = ctx["req_url_params"].get("page", "")

    if not first_page and page:
        page = int(page)
        first_page = page - 1
    elif not page and first_page:
        first_page = int(first_page)
        page = first_page + 1
    elif not first_page and not page:
        first_page = 1
        page = 2
    else:
        first_page = int(first_page)
        page = int(page) + 1
    json_data["first_page"] = first_page
    json_data["page"] = page
    json_data["load_more"] = page <= first_page + 5

    ctx["json_data"] = json_data
    if json_data["list_key"] == 'hotNews':
        ctx["xml_data"] = templates.content_page_hot_list_template.render(
            json_data).encode("utf-8")
    else:
        ctx["xml_data"] = templates.content_page_next_list_template.render(
            json_data).encode("utf-8")
    xml_node = etree.XML(ctx["xml_data"])
    ctx["pb_data"] = xml2pb(xml_node, "append", request.GET.get("id", "-1"),
                            "Ok")
    return gen_response(request, ctx)
示例#8
0
def facebook_stories(request):
    ctx = fetch_context(request)
    json_data = dict()
    handle_fb_request(request, ctx, json_data)
    rsp_url = ctx["rsp_url"]
    open("./facebook.html", "w+").write(ctx["rsp_html"].encode("utf-8"))
    html_ret = run_html(FbFilters.time_line_filter, ctx["rsp_html"],
                        ctx["rsp_url"])
    if rsp_url.find("m.facebook.com/login.php") >= 0:
        ctx["xml_data"] = FbTemplates.time_line_login.render(json_data).encode(
            "utf-8")
        logging.error("can not get facebook_stories")
    else:
        json_data.update(html_ret)
        ctx["json_data"] = json_data
        ctx["xml_data"] = FbTemplates.time_line_template.render(
            json_data).encode("utf-8")
    xml_node = etree.XML(ctx["xml_data"])
    ctx["pb_data"] = xml2pb(xml_node, "replace", "0", "Ok")
    return gen_response(request, ctx)
示例#9
0
def facebook_test(request):
    ctx = fetch_context(request)
    json_data = dict()
    handle_fb_request(request, ctx, json_data, fetch_html=False)

    more_html = open("more2.html", "r").read().decode("utf-8")
    section_html = handle_facebook_json("replace", more_html)
    open("test_section_html.html", "w+").write(section_html.encode("utf-8"))
    html_ret = run_html(FbFilters.time_line_more_filter, section_html,
                        "baidu.com")
    ctx["fetch_html_end_time"] = time.time()
    ctx["rsp_cookie"] = ctx["req_cookie"]
    json_data.update(html_ret)
    ctx["json_data"] = json_data
    json.dump(html_ret, open('test_more_json.txt', 'w+'))
    ctx["xml_data"] = FbTemplates.time_line_more.render(json_data).encode(
        "utf-8")
    open("test_xml_data.txt", "w+").write(ctx["xml_data"])
    xml_node = etree.XML(ctx["xml_data"])

    ctx["pb_data"] = xml2pb(xml_node, "append", "page_list", "Ok")
    return gen_response(request, ctx)
示例#10
0
def uclite_simple_list_page_view(request):
    ctx = fetch_context(request)
    json_data = dict()
    handle_request(request, ctx, json_data)
    json_data.update(
        run_html(Filters.simple_list_page_filter, ctx["rsp_html"],
                 ctx["rsp_url"]))
    json_data["list_id"] = "page_list"
    json_data["disable_refresh"] = True
    max_index = int(ctx["req_params"].get("index", "0"))
    if 'items' in json_data:
        for i, item in enumerate(json_data['items']):
            json_data['items'][i]['index'] = int(
                json_data['items'][i]['index']) + max_index + 1
        json_data['max_index'] = max_index + len(json_data['items'])

    ctx["json_data"] = json_data
    ctx["xml_data"] = templates.simple_list_page_template.render(
        ctx["json_data"]).encode("utf-8")
    xml_node = etree.XML(ctx["xml_data"])
    ctx["pb_data"] = xml2pb(xml_node, "replace", "0", "Ok")
    return gen_response(request, ctx)