OI工具 : BZOJ_PKer – [Python/原创]

思路和一些问题的处理方式来自学长 TonyZhao 的 PKer,但是因为找不到他的 PKer了,还想用,就自己动手写了一个

使用方法已经在帮助文档里注明,请使用 -h,或 --help 查看

# !/usr/bin/env python3
# App name : BZOJ PKer
# App URI : https://yirannn.com/original/BZOJ_PKer/
# Description : A Simple PKer For BZOJ
# Version : 1.0
# Author : Yirannn (With the help of TonyZhao)
# Author URI : https://yirannn.com/
# Author URI : https://zty.ac.cn/

import re
import os
import sys
import ssl
import urllib.request

# 输出函数部分
# ------------------------------------------------------------
def FoutPrint(__List) :
    cnt = 0
    for i in __List :
        cnt += 1
        FileOut.write("%s    " %i)
        if cnt%10 == 0 :
            FileOut.write("\n")
def SoutPrint(__List) :
    cnt = 0;
    for i in __List :
        cnt += 1
        print("%s    " %i, end = '')
        if cnt%10 == 0 :
            print('')

# 输出函数结束
# ------------------------------------------------------------
def getFinish() :
    print("BZOJ PKer By Yirannn")
    print("一个在学长程序指引下完成的PKer")
    print("感谢TonyZhao学长的思路~")
    print("App URI : https://yirannn.com/original/BZOJ_PKer/")
    print("Author URI : https://yirannn.com/")
    print("学长博客 : https://zty.ac.cn/")
    print("如果您有什么好的建议/report Bug")
    print("请联系 i@yirannn.com 或在 URI 页面评论")
# 结束函数部分
# ------------------------------------------------------------

# 结束函数结束
# ------------------------------------------------------------

# 帮助部分
# ------------------------------------------------------------
if (len(sys.argv) != 3 and len(sys.argv) != 4) or sys.argv[1] == '--help' or sys.argv[1] == '-h' :
    getFinish()
    print("使用方法:")
    if os.name == "nt" :
        print("Usage: py %s   ()" % sys.argv[0])
    else :
        print("Usage: python3 %s   ()" % sys.argv[0])
    exit()
# 帮助部分结束
# ------------------------------------------------------------

# 预处理部分
# ------------------------------------------------------------
URL_Userinfo = "https://lydsy.com/JudgeOnline/userinfo.php?user="
FileOut = "PK.out"
Header = {
    "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
}
ssl._create_default_https_context = ssl._create_unverified_context
NameA = sys.argv[1]
NameB = sys.argv[2]
Flag_NeedFile = False
if len(sys.argv) == 4 :
    Flag_NeedFile = True
    File = sys.argv[3]
# 预处理部分结束
# ------------------------------------------------------------


# 爬取部分
# ------------------------------------------------------------
__req = urllib.request.Request(URL_Userinfo+NameA,headers=Header)
__getHtmlA = urllib.request.urlopen(__req).read().decode('utf-8')
__req = urllib.request.Request(URL_Userinfo+NameB,headers=Header)
__getHtmlB = urllib.request.urlopen(__req).read().decode('utf-8')
# 正则表达式 By TonyZhao
getProblemSplit = re.compile(r'function p\(id\){document\.write\(""\+id\+" "\);}\n(.+?)')
getSplitPattern = re.compile(r'p\((.+?)\);')

ProblemsA =getSplitPattern.findall(getProblemSplit.findall(__getHtmlA)[0])
ProblemsB =getSplitPattern.findall(getProblemSplit.findall(__getHtmlB)[0])

__OnlyA = sorted(set(ProblemsA).difference(set(ProblemsB)))
Both  = sorted(set(ProblemsA).intersection(set(ProblemsB)))
__OnlyB = sorted(set(ProblemsB).difference(set(ProblemsA)))

# 爬取部分结束
# ------------------------------------------------------------

# 输出部分
# ------------------------------------------------------------
if Flag_NeedFile :
    FileOut = open(File, "w")
    FileOut.write("Problems Only %s Has Accepted :\n" % NameA)
    FoutPrint(__OnlyA)
    FileOut.write("\nProblems Only %s Has Accepted :\n" % NameB)
    FoutPrint(__OnlyB)
    FileOut.write("\nProblems Both Have Accepted :\n")
    FoutPrint(Both)
else :
    print("Problems Only %s Has Accepted :\n" % NameA, end = '')
    SoutPrint(__OnlyA)
    print("Problems Only %s Has Accepted :\n" % NameB, end = '')
    SoutPrint(__OnlyB)
    FileOut.write("Problems Both Have Accepted :\n")
    SoutPrint(Both)
# 输出部分结束
# ------------------------------------------------------------
getFinish()

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注