From 86e3096ff06245b37977242ce26279f1af733015 Mon Sep 17 00:00:00 2001 From: flt6 <1404262047@qq.com> Date: Sat, 9 Jul 2022 21:43:23 +0800 Subject: [PATCH 1/4] Eng listening cut Former-commit-id: d25aaa7cdc5fe9134fb31097c74d458c1fb06966 Former-commit-id: f8df89bb9bec2cbe16149c56cea5d6f7e5312dfe --- English_Listening_cut/a.exe.REMOVED.git-id | 1 + English_Listening_cut/main.py | 87 ++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 English_Listening_cut/a.exe.REMOVED.git-id create mode 100644 English_Listening_cut/main.py diff --git a/English_Listening_cut/a.exe.REMOVED.git-id b/English_Listening_cut/a.exe.REMOVED.git-id new file mode 100644 index 0000000..6204461 --- /dev/null +++ b/English_Listening_cut/a.exe.REMOVED.git-id @@ -0,0 +1 @@ +6f720344bc9ccc140bde874d65b7173131ca7e99 \ No newline at end of file diff --git a/English_Listening_cut/main.py b/English_Listening_cut/main.py new file mode 100644 index 0000000..dde8f09 --- /dev/null +++ b/English_Listening_cut/main.py @@ -0,0 +1,87 @@ +from sys import argv,exit +from pydub import AudioSegment,silence +from os import path,mkdir,system +from shutil import rmtree +from traceback import print_exc + + +def init(): + if len(argv) != 2: + print("Usage: a.py file.mp3") + exit(1) + return argv[1] + # return "新课程外研高一第32期.mp3" + +def make_dir(pth:str): + if not path.isdir(pth): + try: + mkdir(pth) + except PermissionError: + print("Could not create directory '{pth}' because of permission error.".format(pth=pth)) + exit(-1) + else: + ipt=input(f"'{pth}' exists. Remove it [YES/no]: ") + if ipt == "" or ipt == "yes": + try: + rmtree(pth) + except PermissionError: + print("Could not remove '{pth}' because of permission error.".format(pth=pth)) + exit(-1) + mkdir(pth) + else: + print(f"Warning: Directory '{pth}' exists, which may influence the programm!") + +def cut(file:AudioSegment,length:list[int],keep=300) -> AudioSegment: + maxlen = len(file) + bgn,end=length + if bgn-keep>=0: + bgn-=keep + if end+keep<=maxlen: + end+=keep + return file[bgn:end] + +def main(): + file = init() + NAMES=["BASIC", "1-5", "Others"] + make_dir("OUTPUT") + for i in NAMES: + make_dir(f"OUTPUT/{i}") + print("Reading file ...") + file:AudioSegment = AudioSegment.from_file(file) + print("Detecting audio segments ...") + arr=silence.detect_nonsilent( + file, + silence_thresh=-100, + seek_step=500, + min_silence_len=4000 + ) + print("Cutting audio segments ...") + group=[] + groups=[] + + groups.append([(cut(file,arr[0]),'info'),(cut(file,arr[1]),'example')]) + for i in range(2,2+5): + group.append((cut(file,arr[i]),str(i-1))) + groups.append(group) + group=[] + for i in range(7,len(arr)-1,2): + group.append((cut(file,arr[i]),f"Tips_of_{(i-7)//2+6}")) + group.append((cut(file,arr[i+1]),f"Text_{(i-7)//2+6}")) + groups.append(group) + for i,group in enumerate(groups): + print(f"Saving audio segments '{NAMES[i]}' ...") + for f,name in group: + f.export(f"OUTPUT/{NAMES[i]}/{name}.mp3") + print("Done!") + + +if __name__ == '__main__': + try: + main() + except SystemExit: + system("pause") + except KeyboardInterrupt as e: + raise e + except Exception: + print("An unexpected exception occurred.") + print_exc() From 849f29e16076d71c597eefed94ed2fa770f21cab Mon Sep 17 00:00:00 2001 From: flt6 <1404262047@qq.com> Date: Tue, 16 Aug 2022 12:28:57 +0800 Subject: [PATCH 2/4] Update Former-commit-id: 3bca851bcb1555e7d994460a84389dfd5be02fec Former-commit-id: 9bea7e3ecdab4f1e103a618828d2c6e5ddfd1af4 --- English_Listening_cut/main_json.py | 88 +++++++++++++++++++ recode/recode.py | 103 ++++++++++++++++++++++ zxxk_dl/.gitignore | 3 + zxxk_dl/main.py | 134 +++++++++++++++-------------- 4 files changed, 262 insertions(+), 66 deletions(-) create mode 100644 English_Listening_cut/main_json.py create mode 100644 recode/recode.py create mode 100644 zxxk_dl/.gitignore diff --git a/English_Listening_cut/main_json.py b/English_Listening_cut/main_json.py new file mode 100644 index 0000000..1359dc0 --- /dev/null +++ b/English_Listening_cut/main_json.py @@ -0,0 +1,88 @@ +from sys import argv,exit +from pydub import AudioSegment,silence +from os import path,mkdir,system +from shutil import rmtree +from traceback import print_exc +from json import dumps,loads + + +def init(): + if len(argv) != 2: + print("Usage: a.py file.mp3") + exit(1) + return argv[1] + # return "新课程外研高一第32期.mp3" + +def make_dir(pth:str): + if not path.isdir(pth): + try: + mkdir(pth) + except PermissionError: + print("Could not create directory '{pth}' because of permission error.".format(pth=pth)) + exit(-1) + else: + ipt=input(f"'{pth}' exists. Remove it [YES/no]: ") + if ipt == "" or ipt == "yes": + try: + rmtree(pth) + except PermissionError: + print("Could not remove '{pth}' because of permission error.".format(pth=pth)) + exit(-1) + mkdir(pth) + else: + print(f"Warning: Directory '{pth}' exists, which may influence the programm!") + +def cut(file:AudioSegment,length:list[int],keep=300) -> AudioSegment: + maxlen = len(file) + bgn,end=length + if bgn-keep>=0: + bgn-=keep + if end+keep<=maxlen: + end+=keep + return file[bgn:end] + +def main(): + file = init() + NAMES=["BASIC", "1-5", "Others"] + make_dir("OUTPUT") + for i in NAMES: + make_dir(f"OUTPUT/{i}") + print("Reading file ...") + file:AudioSegment = AudioSegment.from_file(file) + print("Detecting audio segments ...") + arr=silence.detect_nonsilent( + file, + silence_thresh=-100, + seek_step=500, + min_silence_len=4000 + ) + print("Cutting audio segments ...") + group=[] + groups=[] + + groups.append([(cut(file,arr[0]),'info'),(cut(file,arr[1]),'example')]) + for i in range(2,2+5): + group.append((cut(file,arr[i]),str(i-1))) + groups.append(group) + group=[] + for i in range(7,len(arr)-1,2): + group.append((cut(file,arr[i]),f"Tips_of_{(i-7)//2+6}")) + group.append((cut(file,arr[i+1]),f"Text_{(i-7)//2+6}")) + groups.append(group) + for i,group in enumerate(groups): + print(f"Saving audio segments '{NAMES[i]}' ...") + for f,name in group: + f.export(f"OUTPUT/{NAMES[i]}/{name}.mp3") + print("Done!") + + +if __name__ == '__main__': + try: + main() + except SystemExit: + system("pause") + except KeyboardInterrupt as e: + raise e + except Exception: + print("An unexpected exception occurred.") + print_exc() diff --git a/recode/recode.py b/recode/recode.py new file mode 100644 index 0000000..d51bbcd --- /dev/null +++ b/recode/recode.py @@ -0,0 +1,103 @@ +from sys import argv +from os.path import isfile, isdir +from os import mkdir +from json import dump, load +HELP = ''' +Usage: recode.py / +Options: + If options is specified, program will only save configs. + + -i: input file code. (eg. utf-8) (Default: test all known codes) + -o: output file code. (Default: utf-8) + -c: codes that try to convert from. (Default: test all known codes) + split by ','. (eg. utf-8,gbk,gb2312) + -r: save the output file in the specified directory. (Default: out) + -s: show all known codes. (Don't use this with others) +''' +OPTIONS = ["-i", "-o", "-c", "-s", "-r"] + +CODES = ['ascii', 'big5', 'big5hkscs', 'cp037', 'cp273', 'cp424', 'cp437', 'cp500', 'cp720', 'cp737', 'cp775', 'cp850', 'cp852', 'cp855', 'cp856', 'cp857', 'cp858', 'cp860', 'cp861', 'cp862', 'cp863', 'cp864', 'cp865', 'cp866', 'cp869', 'cp874', 'cp875', 'cp932', 'cp949', 'cp950', 'cp1006', 'cp1026', 'cp1125', 'cp1140', 'cp1250', 'cp1251', 'cp1252', 'cp1253', 'cp1254', 'cp1255', 'cp1256', 'cp1257', 'cp1258', 'euc_jp', 'euc_jis_2004', 'euc_jisx0213', 'euc_kr', 'gb2312', 'gbk', 'gb18030', 'hz', 'iso2022_jp', 'iso2022_jp_1', 'iso2022_jp_2', 'iso2022_jp_2004', + 'iso2022_jp_3', 'iso2022_jp_ext', 'iso2022_kr', 'latin_1', 'iso8859_2', 'iso8859_3', 'iso8859_4', 'iso8859_5', 'iso8859_6', 'iso8859_7', 'iso8859_8', 'iso8859_9', 'iso8859_10', 'iso8859_11', 'iso8859_13', 'iso8859_14', 'iso8859_15', 'iso8859_16', 'johab', 'koi8_r', 'koi8_t', 'koi8_u', 'kz1048', 'mac_cyrillic', 'mac_greek', 'mac_iceland', 'mac_latin2', 'mac_roman', 'mac_turkish', 'ptcp154', 'shift_jis', 'shift_jis_2004', 'shift_jisx0213', 'utf_32', 'utf_32_be', 'utf_32_le', 'utf_16', 'utf_16_be', 'utf_16_le', 'utf_7', 'utf_8', 'utf_8_sig'] +DEFALT = {'ipt': None, 'opt': 'utf-8', 'test': None, 'write': 'out'} + + +def setOption(arg): + if arg[0] == '-s': + for i in CODES: + print("%15s" % i, end=' ') + return + opt = arg[::2] + val = arg[1:][::2] + option = DEFALT.copy() + trans = {'-i': 'ipt', '-o': 'opt', '-c': 'test', "-r": "write"} + for o, v in zip(opt, val): + if o == '-c': + option[trans[o]] = v.split(',') + else: + option[trans[o]] = v + with open("config.json", "w") as f: + dump(option, f) + + +def main(files): + if isfile("config.json"): + try: + with open("config.json", "r") as f: + config = load(f) + except Exception: + print("Can't read config file.") + config = DEFALT + else: + print("No config file provided.") + config = DEFALT + + codes = CODES if config["test"] is None else config["test"] + outcode = config["opt"] + outdir = config["write"] + + if not isdir(outdir): + mkdir(outdir) + + for file in files: + if isfile(outdir+'/'+file): + print(f"File '{outdir+'/'+file} exists. Ignore.") + continue + if config["ipt"] is None: + for code in codes: + if recode(file, outdir, code, outcode, config["write"]): + break + else: + if not recode(file, outdir, config["ipt"], outcode): + print("Could not convert '%s' from '%s' to '%s'" % + (file, config["ipt"], outcode)) + else: + print(f"Success to convert {file}") + + +def recode(file, opt, src, to) -> bool: + try: + with open(file, 'r', encoding=src) as f: + tem = f.read() + except KeyboardInterrupt: + exit(2) + except Exception: + print("Can't open file.") + return False + try: + with open(opt+'/'+file, 'w', encoding=to) as f: + f.write(tem) + except KeyboardInterrupt: + exit(2) + except Exception: + print("Can't write file.") + return True + + +if __name__ == '__main__': + if len(argv) == 1: + print(HELP) + exit(1) + elif argv[1] in OPTIONS: + setOption(argv[1:]) + else: + main(argv[1:]) diff --git a/zxxk_dl/.gitignore b/zxxk_dl/.gitignore new file mode 100644 index 0000000..9edb8ed --- /dev/null +++ b/zxxk_dl/.gitignore @@ -0,0 +1,3 @@ +*.html +*.pdf +*.docx \ No newline at end of file diff --git a/zxxk_dl/main.py b/zxxk_dl/main.py index b039c0a..1733b64 100644 --- a/zxxk_dl/main.py +++ b/zxxk_dl/main.py @@ -1,66 +1,68 @@ -import requests -from time import strftime -from re import findall - -HTML_FORMAT =''' - - - -{title} - - - -{body} - - - -''' - -def writefile(filename,text): - with open(filename+'.html', 'w') as f: - f.write(text) - - -def main(): - softID=input("ID: ") - url = "https://www.zxxk.com/soft/Preview/FirstLoadPreviewJson?softID={}&type=3&product=1&v=2&FullPreview=true" - response = requests.get(url.format(softID)) - if response.status_code!=200: - print("ERROR") - print(response.status_code) - return -1 - ret=response.json()["data"] - if not ret["IsSuccess"]: - print("ERROR: IsSuccess option is not true") - print(ret) - if not ret['IsRar']: - print("Not rar") - print("TotalPage=%d" % ret['TotalPage']) - print("SoftExt=%s" % ret['SoftExt']) - html=response["Html"] - # replace "data-original" to "src" for showing in browser - html=html.replace("data-original", "src") - writefile(strftime("%Y%m%d-%H:%M"),html) - else: - print("is RAR") - rar=ret['rarPreviewInfo'] - for file in rar: - html=file["Html"] - title=file["SoftName"] - # replace "data-original" to "src" for showing in browser - # html=html.replace("data-original", "src") - urls=findall("(?<=data-original=\")https://preview.xkw.com/.+(?=\")",html) - l=[] - for url in urls: - page=requests.get(url,cookies=response.cookies) - if not page.status_code==200: - print(page) - print(page.status_code) - print(page.text) - assert page.status_code==200 - l.append(page.text) - format_html=HTML_FORMAT.format(title=title,body="\n".join(l)) - writefile(title,format_html) - -if __name__ == "__main__": - main() +import requests +from time import strftime +import re + +HTML_FORMAT =''' + + + +{title} + + + +{body} + + + +''' + +def writefile(filename,text): + filename=re.sub(r'''[\*\/\\\|\<\>\? \:\.\'\"\!]''',"",filename) + with open(filename+'.html', 'w') as f: + f.write(text) + + +def main(): + softID=input("ID: ") + url = "https://www.zxxk.com/soft/Preview/FirstLoadPreviewJson?softID={}&fileaddress=&type=3&product=1&v=2&FullPreview=true" + response = requests.get(url.format(softID)) + if response.status_code!=200: + print("ERROR") + print(response.status_code) + return -1 + ret=response.json()["data"] + if not ret["IsSuccess"]: + print("ERROR: IsSuccess option is not true") + print(ret) + if not ret['IsRar']: + print("Not rar") + print("TotalPage=%d" % ret['TotalPage']) + print("SoftExt=%s" % ret['SoftExt']) + html=ret["Html"] + # replace "data-original" to "src" for showing in browser + html=html.replace("data-original", "src") + writefile(strftime("%Y%m%d-%H:%M"),html) + else: + print("is RAR") + rar=ret['rarPreviewInfo'] + for file in rar: + html=file["Html"] + title=file["SoftName"] + # replace "data-original" to "src" for showing in browser + html=html.replace("data-original", "src") + # urls=findall("(?<=data-original=\")https://preview.xkw.com/.+(?=\")",html) + # l=[] + # for url in urls: + # page=requests.get(url,cookies=response.cookies) + # if not page.status_code==200: + # print(page) + # print(page.status_code) + # print(page.text) + # print(page) + # assert page.status_code==200 + # l.append(page.text) + # format_html=HTML_FORMAT.format(title=title,body="\n".join(l)) + writefile(title,html) + +if __name__ == "__main__": + main() From 606861b3a1303f5be348093351bafdd552e54a01 Mon Sep 17 00:00:00 2001 From: flt6 <1404262047@qq.com> Date: Fri, 23 Sep 2022 10:29:05 +0800 Subject: [PATCH 3/4] update Former-commit-id: 8d2717060dc7314535a6422433dab9027b830b4f Former-commit-id: 159f1cb3ea98a03db9bfad177cdf25b5b953b10a --- pinyin/gen.py | 53 +++++++++++++++++++++++++++++++ rand/main.py | 29 +++++++++++++++++ recode/recode_new.py | 58 ++++++++++++++++++++++++++++++++++ video/cut.py | 32 +++++++++++++++++++ wjx/main.py | 75 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 247 insertions(+) create mode 100644 pinyin/gen.py create mode 100644 rand/main.py create mode 100644 recode/recode_new.py create mode 100644 video/cut.py create mode 100644 wjx/main.py diff --git a/pinyin/gen.py b/pinyin/gen.py new file mode 100644 index 0000000..d8341d0 --- /dev/null +++ b/pinyin/gen.py @@ -0,0 +1,53 @@ +t='''毕思淼 +毕一聪 +丛金旺 +崔子豪 +樊乐天 +高镆 +黄卓琳 +姜樱楠 +焦祺 +李柏畅 +李南卓阳 +李善伊 +李怡萱 +李语恒 +刘宇航 +刘雨鑫 +刘卓 +娄晴 +洛艺伟 +马卉冉 +潘一鸣 +庞惠铭 +乔旺源 +沈洁 +宋佳怡 +宋雨蔓 +宋智宪 +苏振宇 +王梁宇 +王明仁 +王耀增 +王子来 +吴庆波 +徐子灏 +阎展博 +杨颜聪 +于诗澳 +于世函 +张濠亿 +张日昊 +张姝肜 +张文桦 +张潇艺 +张晓轩 +张妍 +周含笑 +周巧冉''' +from pypinyin import pinyin +from pypinyin import Style +l=t.splitlines() +for text in l: + tem=pinyin(text,style=Style.FIRST_LETTER) + print(''.join([i[0] for i in tem])) \ No newline at end of file diff --git a/rand/main.py b/rand/main.py new file mode 100644 index 0000000..f907da7 --- /dev/null +++ b/rand/main.py @@ -0,0 +1,29 @@ +from random import randint + +bgn,end=[int(i) for i in input("Option: Input random area(like 21-43): ").split("-")] +obj=int(input("Option: Amount: ")) +repeat=input("Option: Allow repeat:\nAccept: T(true) (defalt), F(false)\n").lower() +if repeat == "": + repeat=True +else: + if repeat in ["t","true"]: + repeat=True + elif repeat in ["f","false"]: + repeat=False + else: + input("Unsupported option.") +l=[] +if repeat: + l=[randint(bgn,end) for i in range(obj)] +else: + i=0 + while len(l)/ +''' +TARGET = 'utf-8' +OUTDIR = "Output" + + +def main(files): + if not isdir(OUTDIR): + mkdir(OUTDIR) + + for file in files: + path = abspath(file) + path = path.replace("\\", "/") + path = path.split('/') + path = '/'.join(path[:-1])+"/"+OUTDIR+"/"+path[-1] + if isfile(path): + print(Fore.YELLOW+f"WARN: File '{path} exists. Ignore.") + continue + recode(file,path) + + +def recode(file,path): + try: + with open(file, 'rb') as f: + tem = f.read() + except Exception as e: + print(Fore.RED+f"ERROR: Can't open file '{file}'") + return + ret = detect(tem) + if ret["encoding"] is None: + print(Fore.RED+"ERROR: Cannot detect encoding of `%s`" % file) + return + + with open(file, 'r',encoding=ret["encoding"]) as f: + tem = f.read() + + if ret['confidence'] < 0.8: + print(Fore.YELLOW+"WARN: File `%s` confidence is lower than 0.8. Recognized as `%s`."%(file,ret["encoding"])) + + with open(path, 'w', encoding=TARGET) as f: + f.write(tem) + print(Fore.LIGHTBLUE_EX+"INFO: Success for `%s` with confidence %0.1f%%"%(file,ret["confidence"]*100)) + + +if __name__ == '__main__': + init(autoreset=True) + if len(argv) == 1: + print(HELP) + else: + main(argv[1:]) + print("------------------------") + input("Press enter to exit") diff --git a/video/cut.py b/video/cut.py new file mode 100644 index 0000000..f6e48cb --- /dev/null +++ b/video/cut.py @@ -0,0 +1,32 @@ +from sys import argv +from subprocess import run +from os import system + +if len(argv) != 2: + print("Usage: ") + exit(1) +file = argv[1] +tem=file.split(".") +name = ".".join(tem[:-1]) +o = tem[-1] +bgn = input("bgn: ") +if bgn=="": + bgn="0" +to = input("to: ") +cmd = [ + r'E:\green\ffmpeg\bin\ffmpeg.exe', + '-i', + file, + '-ss', + bgn, + '-to', + to, + '-c', + 'copy', + name+"_cut."+o +] +print(cmd) +# run("pause") +ret = run(cmd) +print("ffmpeg finished with code",ret.returncode) +system("pause") \ No newline at end of file diff --git a/wjx/main.py b/wjx/main.py new file mode 100644 index 0000000..0eaa8c7 --- /dev/null +++ b/wjx/main.py @@ -0,0 +1,75 @@ +from requests import Response,Session +from re import search +from json import dumps + +headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.42' +} +s=Session() + +def chk(resp:Response): + if resp.status_code != 200: + print("Error: %d" % resp.status_code) + exit(1) + return resp.text + +def get(url,**kwargs): + ret = s.get(url,allow_redirects=False,headers=headers,**kwargs) + jar = ret.cookies + if ret.status_code == 302: + url2 = ret.headers['Location'] + return get(url2, cookies=jar) + elif ret.status_code != 200: + print("Error: %d" % ret.status_code) + exit(1) + return ret + +def login(username, password): + # 问卷星竟然明文发送密码 + ret = chk(s.get("https://www.wjx.cn/login.aspx")) + v1 = search('(?<=())',ret) + if v1 is not None: + v1 = v1.group() + v2 = search('(?<=())',ret) + if v2 is not None: + v2 = v2.group() + v3 = search('(?<=())',ret) + if v3 is not None: + v3 = v3.group() + print(v1,v2,v3) + with open("tmp.html", "w",encoding="utf-8") as f: + print(ret,file=f) + d={ + "__VIEWSTATE": v1, + "__VIEWSTATEGENERATOR": v2, + "__EVENTVALIDATION": v3, + "UserName": username, + "Password": password, + "LoginButton": "登录" + } + # d={ + # "__VIEWSTATE": "/wEPDwULLTIxMTQ1NzY4NzFkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBQpSZW1lbWJlck1ldLwU4qgz33Rji8zou8eAENNib4k=", + # "__VIEWSTATEGENERATOR":"C2EE9ABB", + # "__EVENTVALIDATION": "/wEdAAfxrqR6nVOy3mBYlwdwNQ3ZR1LBKX1P1xh290RQyTesRRHS0B3lkDg8wcTlzQR027xRgZ0GCHKgt6QG86UlMSuIXArz/WCefbk6V2VE3Ih52ScdcjStD50aK/ZrfWs/uQXcqaj6i4HaaYTcyD0yJuxuNMxKZaXzJnI0VXVv9OL2HZrk5tk=", + # "UserName": username, + # "Password": password, + # "LoginButton": "登录" + # } + ret = s.post("https://www.wjx.cn/Login.aspx",json=dumps(d)) + ret.raise_for_status() + +def getlist(id): + ret = s.get( + "https://www.wjx.cn/wjx/activitystat/viewstatsummary.aspx", + params={"activity":id}, + headers=headers + ) + ret = chk(ret) + find = search(r'(?<=(var ids = "))[\d,]+(?=(";))',ret) + assert find is not None,ret + return find.group().split(",") + +if __name__ == "__main__": + login("flt","***REMOVED***") + print(s.cookies) + print(getlist("184412487")) \ No newline at end of file From 3356e36e7304fe70bbf854dbc20e89a2155ceada Mon Sep 17 00:00:00 2001 From: flt6 <1404262047@qq.com> Date: Fri, 7 Oct 2022 13:39:52 +0800 Subject: [PATCH 4/4] up Former-commit-id: 3beec1f80e66a86223b0f0f5c98a1e1405a90a29 Former-commit-id: 39d11dd75ed5b66095bb2603c54ca790236af6af --- move_warn/t2.py | 97 +++++++++++++++ recode/Output/test.txt | 1 + recode/test.txt | 1 + wjx/tmp.html | 275 +++++++++++++++++++++++++++++++++++++++++ wjx/tmp.py | 12 ++ 5 files changed, 386 insertions(+) create mode 100644 move_warn/t2.py create mode 100644 recode/Output/test.txt create mode 100644 recode/test.txt create mode 100644 wjx/tmp.html create mode 100644 wjx/tmp.py diff --git a/move_warn/t2.py b/move_warn/t2.py new file mode 100644 index 0000000..3594004 --- /dev/null +++ b/move_warn/t2.py @@ -0,0 +1,97 @@ +import cv2 +import numpy as np +from winsound import PlaySound,SND_ALIAS,SND_ASYNC +from time import time +# Beep(500,500) + +# camera = cv2.VideoCapture(0) # 参数0表示第一个摄像头 +# camera = cv2.VideoCapture("opt.flv") +camera = cv2.VideoCapture("http://192.168.124.17:8081/live.flv") +# 判断视频是否打开 +if (camera.isOpened()): + print('Open') +else: + print('摄像头未打开') + +# 测试用,查看视频size +size = (int(camera.get(cv2.CAP_PROP_FRAME_WIDTH)), int(camera.get(cv2.CAP_PROP_FRAME_HEIGHT))) +print('size:'+repr(size)) + +es = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (9, 4)) +kernel = np.ones((5, 5), np.uint8) +background = None +cnt = 0 +tot = 0 +last = time() +mask = np.array([(0, 0),(282, 0),(282, 26),(0, 26)]) + +# cv2.waitKey(5) + +while True: +# 读取视频流 + try: + grabbed, frame_lwpCV = camera.read() + cv2.waitKey(5) + cv2.fillConvexPoly(frame_lwpCV, mask,(0,255,0)) + cv2.imshow("src",frame_lwpCV) + except cv2.error: + print("ignore this frame") + continue +# 对帧进行预处理,先转灰度图,再进行高斯滤波。 +# 用高斯滤波进行模糊处理,进行处理的原因:每个输入的视频都会因自然震动、光照变化或者摄像头本身等原因而产生噪声。对噪声进行平滑是为了避免在运动和跟踪时将其检测出来。 + gray_lwpCV = cv2.cvtColor(frame_lwpCV, cv2.COLOR_BGR2GRAY) + gray_lwpCV = cv2.GaussianBlur(gray_lwpCV, (21, 21), 0) +# 将第一帧设置为整个输入的背景 + if background is None: + background = gray_lwpCV + continue +# 对于每个从背景之后读取的帧都会计算其与北京之间的差异,并得到一个差分图(different map)。 +# 还需要应用阈值来得到一幅黑白图像,并通过下面代码来膨胀(dilate)图像,从而对孔(hole)和缺陷(imperfection)进行归一化处理 + diff = cv2.absdiff(background, gray_lwpCV) + # cv2.imshow('abs', diff) + diff = cv2.threshold(diff, 25, 255, cv2.THRESH_BINARY)[1] # 二值化阈值处理 + diff = cv2.dilate(diff, es, iterations=2) # 形态学膨胀 +# 显示矩形框 + contours, hierarchy = cv2.findContours(diff.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) # 该函数计算一幅图像中目标的轮廓 + contours = [c for c in contours if cv2.contourArea(c) >= 1500] + # 对于矩形区域,只显示大于给定阈值的轮廓,所以一些微小的变化不会显示。对于光照不变和噪声低的摄像头可不设定轮廓最小尺寸的阈值 + total=0 + for c in contours: + # if cv2.contourArea(c) < 1500: + # continue + total += cv2.contourArea(c) + (x, y, w, h) = cv2.boundingRect(c) # 该函数计算矩形的边界框 + cv2.rectangle(frame_lwpCV, (x, y), (x+w, y+h), (0, 255, 0), 2) + + cv2.imshow('contours', frame_lwpCV) + cv2.imshow('dis', diff) + + if len(contours)>0 and total>10000: + cnt+=1 + if cnt > 5: + if time()-last<5: + print(time(),last) + tot+=1 + else: + print("else: ",time(),last) + tot = 1 + last = time() + cnt = 0 + print("################################") + PlaySound("SystemAsterisk",SND_ALIAS|SND_ASYNC) + background = gray_lwpCV + else: + cnt=cnt-1 if cnt>0 else 0 + + if tot>4: + PlaySound("SystemHand",SND_ALIAS) + exit() + + key = cv2.waitKey(1) & 0xFF +# 按'L'健退出循环 + if key == ord('L'): + break + + +camera.release() +cv2.destroyAllWindows() diff --git a/recode/Output/test.txt b/recode/Output/test.txt new file mode 100644 index 0000000..da01559 --- /dev/null +++ b/recode/Output/test.txt @@ -0,0 +1 @@ +ASD¼Ñ¼ÑDSA \ No newline at end of file diff --git a/recode/test.txt b/recode/test.txt new file mode 100644 index 0000000..9b880cb --- /dev/null +++ b/recode/test.txt @@ -0,0 +1 @@ +ASDѼDSA \ No newline at end of file diff --git a/wjx/tmp.html b/wjx/tmp.html new file mode 100644 index 0000000..0219f13 --- /dev/null +++ b/wjx/tmp.html @@ -0,0 +1,275 @@ + + + + + + + 登录页面_问卷星 + + + + + + + + +
+
+ +
+ +
+ + + +
+
+ +
+
+
+ + +
    +
  • + + +
    +
  • +
  • + + +
  • +
  • + +
  • + + + +
+
+ + + + + + + 忘记用户名/密码? +
+ + +
+
+ + 立即注册 + + +
+
+
+
《登顶武功山》
+
拍摄于问卷星团队二月徒步之旅
+
+
+
+ + + diff --git a/wjx/tmp.py b/wjx/tmp.py new file mode 100644 index 0000000..5d47726 --- /dev/null +++ b/wjx/tmp.py @@ -0,0 +1,12 @@ +import requests + +url = "https://www.wjx.cn/login.aspx" + +payload={} +headers = { + 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.42' +} + +response = requests.request("GET", url, headers=headers, data=payload) + +print(response.text) \ No newline at end of file