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())
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)
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:])
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
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
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]
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]
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]
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]
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]
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
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)
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
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]
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)
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
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
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
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