コード例 #1
0
def th11decodedata(file, buffer, flength):
    length = unsigned_int(buffer, 0x1c)
    dlength = unsigned_int(buffer, 0x20)
    decodedata = bytearray(dlength)
    rawdata = bytearray(buffer[0x24:])

    decode(rawdata, length, 0x800, 0xaa, 0xe1)
    decode(rawdata, length, 0x40, 0x3d, 0x7a)
    decompress(rawdata, decodedata, length)

    return decodedata
コード例 #2
0
def page_count():
    data = decompress(spide(lightoj_userlist_url))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    page = match(lightoj_page_count_pattern, data)[-1:][0]
    return int(page.lstrip().rstrip())
コード例 #3
0
def spide_for_lightoj(user_list):
    data = parse.urlencode(post_data).encode('utf-8')
    cookie = cookiejar.CookieJar()
    opener = request.build_opener(request.HTTPCookieProcessor(cookie))
    request.install_opener(opener)
    try:
        Req = request.Request(url=lightoj_login_url, data=data, headers=headers)
        Res = request.urlopen(Req)
    except Exception:
        return user_list
    else:
        page_tot = page_count()
        if page_tot == get_data_failed:
            return
        for page in range(page_tot):
            url = lightoj_userlist_url + str(page*50+1) 
            data = decompress(spide(url))
            if data is None:
                continue
            data = data.decode('utf-8')
            user_one = match(lightoj_tr_data_one_pattern, data)
            user_two = match(lightoj_tr_data_two_pattern, data)
            get(user_list, user_one, lightoj_user_data_one_pattern,
                lightoj_td_data_one_pattern)
            get(user_list, user_two, lightoj_user_data_two_pattern,
                lightoj_td_data_two_pattern)
コード例 #4
0
def get_page_count(url):
    data = decompress(spide(url+'1'))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    page_info = match(noj_page_count_pattern, data)[0]
    char_pos = page_info.index('=')
    return int(page_info[char_pos+1:])
コード例 #5
0
def spide_for_bzoj(username):
    url = bzoj_url
    data = decompress(spide(url + username))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    if data[-13:-1] == 'No such User':
        return match_user_failed
    ac_number = match(bzoj_ac_pattern, data)[0]
    return ac_number
コード例 #6
0
ファイル: bzoj_count.py プロジェクト: ppaydd/problem_count
def spide_for_bzoj(username):
    url = bzoj_url
    data = decompress(spide(url+username))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    if data[-13:-1] == 'No such User':
        return match_user_failed
    ac_number = match(bzoj_ac_pattern, data)[0]
    return ac_number
コード例 #7
0
ファイル: zoj_count.py プロジェクト: ppaydd/problem_count
def get_user_url(username):
    url = zoj_url
    data = decompress(spide(url.format(username)))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    user_url = match(zoj_user_pattern, data)
    if user_url is None or len(user_url) == 0:
        return match_user_failed
    return 'http://www.icpc.moe' + user_url[0]
コード例 #8
0
ファイル: fzu_count.py プロジェクト: ppaydd/problem_count
def spide_for_fzu(username):
    url = fzu_url + username
    data = decompress(spide(url))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    ac_number = match(fzu_ac_number_pattern, data)
    if ac_number is None or len(ac_number) < 1:
        return match_user_failed
    return ac_number[1]
コード例 #9
0
ファイル: zoj_count.py プロジェクト: ppaydd/problem_count
def get_user_url(username):
    url = zoj_url
    data = decompress(spide(url.format(username)))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    user_url = match(zoj_user_pattern, data)
    if user_url is None or len(user_url) == 0:
        return match_user_failed
    return 'http://www.icpc.moe' + user_url[0]
コード例 #10
0
def test(file):
    from common import entry
    file, buffer, flength = entry(file)

    length = unsigned_int(buffer, 0x1c)
    dlength = unsigned_int(buffer, 0x20)
    decodedata = bytearray(dlength)
    rawdata = bytearray(buffer[0x24:])

    def assert_file_eq(obj, path):
        from utils import find_last_match
        with open(path, 'rb') as f:
            cont = f.read()
        cut = min(len(obj), len(cont))
        assert obj[:cut] == cont[:cut]

    #assert_file_eq(rawdata, '{}.raw.rawdata1'.format(file))

    decode(rawdata, length, 0x400, 0xaa, 0xe1)

    #assert_file_eq(rawdata, '{}.raw.rawdata2'.format(file))

    decode(rawdata, length, 0x80, 0x3d, 0x7a)

    #assert_file_eq(rawdata, '{}.raw.rawdata3'.format(file))

    decompress(rawdata, decodedata, length)

    assert_file_eq(decodedata, '{}.raw'.format(file))

    try:
        assert_file_eq(decodedata, '{}.raw'.format(file))
    except AssertionError:
        rawdata = bytearray(buffer[0x24:])

        assert_file_eq(rawdata, '{}.raw.rawdata1'.format(file))
        decode(rawdata, length, 0x400, 0xaa, 0xe1)
        assert_file_eq(rawdata, '{}.raw.rawdata2'.format(file))
        decode(rawdata, length, 0x80, 0x3d, 0x7a)
        assert_file_eq(rawdata, '{}.raw.rawdata3'.format(file))

    print('test pass')
コード例 #11
0
ファイル: sgu_count.py プロジェクト: ppaydd/problem_count
def spide_for_sgu(username):
    url = sgu_url
    data = decompress(spide(url+username))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    table_data = match(sgu_table_pattern, data)
    if table_data is None or len(table_data) < 1:
        return match_user_failed
    tr_data = match(sgu_tr_pattern, table_data[0])[17]
    return match(sgu_ac_number_pattern, tr_data)[0]
コード例 #12
0
ファイル: acdream_count.py プロジェクト: ppaydd/problem_count
def spide_for_acdream(username):
    url = acdream_url
    data = decompress(spide(url+username))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    ul_data = match(acdream_ul_pattern, data)
    if ul_data is None or len(ul_data) < 1:
        return match_user_failed
    ul_data = ul_data[0]
    ac_number = match(acdream_ac_number_pattern, ul_data)
    return ac_number[0]
コード例 #13
0
ファイル: acdream_count.py プロジェクト: ppaydd/problem_count
def spide_for_acdream(username):
    url = acdream_url
    data = decompress(spide(url + username))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    ul_data = match(acdream_ul_pattern, data)
    if ul_data is None or len(ul_data) < 1:
        return match_user_failed
    ul_data = ul_data[0]
    ac_number = match(acdream_ac_number_pattern, ul_data)
    return ac_number[0]
コード例 #14
0
def find_user(user_list, page_url):
    data = decompress(spide(page_url))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    td_data = match(noj_td_pattern, data)
    for i in range(2, len(td_data), 6):
        cur_username = match(noj_username_pattern, td_data[i])[0]
        print('get ', cur_username)
        if int(td_data[i+3]) == 0:
            return False
        user_list.append((cur_username, td_data[i+3]))
    return True
コード例 #15
0
def spide_for_codeforces(username):
    url = codeforces_url.format(username)
    data = decompress(spide(url))
    if data is None:
        return get_data_failed
    json_data = json.loads(data.decode('utf-8'))
    ac_set = set()
    for key, value in json_data.items():
        if key != 'status':
            for submit in value:
                if submit['verdict'] == 'OK' and submit['problem']['name'] not in ac_set:
                    ac_set |= {submit['problem']['name']}
            break
    return len(ac_set)
コード例 #16
0
def spide_for_hdu(username):
    url = hdu_url + username
    data = decompress(spide(url))
    if data is None:
        return get_data_failed
    data = data.decode('gb2312')
    table_data = match(hdu_table_pattern, data)
    if table_data is None:
        return match_user_failed
    table_data = table_data[0]
    td_data = match(hdu_td_pattern, table_data)
    for i in range(2, len(td_data), 6):
        if td_data[i] == username:
            return td_data[i + 3]
    return match_user_failed
コード例 #17
0
ファイル: zoj_count.py プロジェクト: ppaydd/problem_count
def spide_for_zoj(username):
    url = zoj_url
    url = get_user_url(username)
    if url == get_data_failed:
        return get_data_failed
    if url == match_user_failed:
        return match_user_failed
    data = decompress(spide(url.format(username)))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    div_data = match(zoj_div_pattern, data)[0]
    ac_number = match(zoj_ac_pattern, div_data)[0]
    char_pos = ac_number.index('/')
    return ac_number[:char_pos]
コード例 #18
0
def spide_for_codeforces(username):
    url = codeforces_url.format(username)
    data = decompress(spide(url))
    if data is None:
        return get_data_failed
    json_data = json.loads(data.decode('utf-8'))
    ac_set = set()
    for key, value in json_data.items():
        if key != 'status':
            for submit in value:
                if submit['verdict'] == 'OK' and submit['problem'][
                        'name'] not in ac_set:
                    ac_set |= {submit['problem']['name']}
            break
    return len(ac_set)
コード例 #19
0
ファイル: hdu_count.py プロジェクト: ppaydd/problem_count
def spide_for_hdu(username):
    url = hdu_url + username
    data = decompress(spide(url))
    if data is None:
        return get_data_failed
    data = data.decode('gb2312') 
    table_data = match(hdu_table_pattern, data)
    if table_data is None:
        return match_user_failed
    table_data = table_data[0]
    td_data = match(hdu_td_pattern, table_data)
    for i in range(2, len(td_data), 6):
        if td_data[i] == username:
            return td_data[i+3]
    return match_user_failed
コード例 #20
0
ファイル: zoj_count.py プロジェクト: ppaydd/problem_count
def spide_for_zoj(username):
    url = zoj_url
    url = get_user_url(username) 
    if url == get_data_failed:
        return get_data_failed
    if url == match_user_failed:
        return match_user_failed
    data = decompress(spide(url.format(username)))
    if data is None: 
        return get_data_failed
    data = data.decode('utf-8')
    div_data = match(zoj_div_pattern, data)[0]
    ac_number = match(zoj_ac_pattern, div_data)[0]
    char_pos = ac_number.index('/')
    return ac_number[:char_pos]
コード例 #21
0
ファイル: ural_count.py プロジェクト: ppaydd/problem_count
def spide_for_ural(username):
    url = ural_url
    data = decompress(spide(url + username))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    table_data = match(ural_table_pattern, data)
    if table_data is None:
        return match_user_failed
    table_data = table_data[0]
    tr_data = match(ural_tr_pattern, table_data)[1:]
    for item in tr_data:
        cur_username = match(ural_user_pattern, item)[0]
        if cur_username == username:
            ac_number = match(ural_ac_number_pattern, item)[2]
            return ac_number
    return match_user_failed
コード例 #22
0
ファイル: ural_count.py プロジェクト: ppaydd/problem_count
def spide_for_ural(username):
    url = ural_url
    data = decompress(spide(url+username))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    table_data = match(ural_table_pattern, data)
    if table_data is None:
        return match_user_failed
    table_data = table_data[0]
    tr_data = match(ural_tr_pattern, table_data)[1:]
    for item in tr_data:
        cur_username = match(ural_user_pattern, item)[0]
        if cur_username == username:
            ac_number = match(ural_ac_number_pattern, item)[2]
            return ac_number
    return match_user_failed
コード例 #23
0
def spide_for_poj(username):
    url = poj_url
    if len(username) <= 1:
        return match_user_failed
    data = decompress(spide(url.format(username)))
    if data is None:
        return get_data_failed
    data = data.decode('utf-8')
    table_data = match(poj_table_pattern, data)
    if table_data is None or len(table_data) < 1:
        return match_user_failed
    td_data = match(poj_td_pattern, table_data[0]) 
    for i in range(0, len(td_data), 6):
        cur_username = match(poj_username_pattern, td_data[i])[0]
        if cur_username.lower() != username.lower():
            continue
        return td_data[i+4]
    return match_user_failed