コード例 #1
0
def get_file():
    #
    res = dict()
    #
    # file-path
    temp_dir = "/search/chenzhengtong/weixin-recom/tempFiles/"
    full_path = temp_dir + "single.csv"
    f = open(full_path)
    lines = f.readlines(100000)
    #
    format_list = ["main_type", "title", "url", "level"]
    #
    if not lines:
        print "error"
    else:
        try:
            #
            conn, cur = ADMIN_OA.get_conn_for_mysql_oa()
            #
            for each_line in lines:
                line = str.rstrip(each_line)
                temp_list = line.split(",")
                #
                content_list = list()
                content_list.append(
                    unicode(temp_list[0], "gbk").encode("gbk")
                )
                content_list.append(
                    unicode(temp_list[1], "gbk").encode("gbk")
                )
                content_list.append(
                    temp_list[2].split(CONST.OPENID_PREFIX)[1]
                )
                content_list.append(temp_list[3])
                #
                sql_ui = ADMIN_OA.get_ui_sql(content_list)
                #print sql_ui
                #
                cur.execute(sql_ui)
            #
            cur.close()
            conn.close()
            #
            UTIL.append_result_ok(res)
        except Exception, e:
            #
            UTIL.append_result_error(res, e)