Knight000's Blog

随缘写写,不定时更新

0%

我也不知道写了什么

说明

这里收录我写的一些迷惑东西,现在主要是神奇的想法还有一些坑

Python

Windows下查询指定端口占用

感觉没啥必要不过就当作是练练subprocess吧

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import subprocess
PORT = input('请输入要查询的端口号:')
netstat = subprocess.check_output(
f'netstat -ano|findstr \"{PORT}\"|findstr \"LISTENING\"', shell=True).decode("utf-8").split() # 用已封装好的方法
if netstat == []:
print('端口未被占用')
else:
print(f'端口号包含{PORT},查询开始',end="\n<------------------------------------------------------------------------->\n")
for i in range(0, len(netstat), 5):
print(
f'协议:{netstat[i+0]} 本地地址:{netstat[i+1]} 外部地址:{netstat[i+2]} PID:{netstat[i+4]}')
tasklist = subprocess.Popen(
f'tasklist|findstr \"{netstat[i+4]}\"', stdout=subprocess.PIPE, shell=True).stdout.read().decode("utf-8").split() # 直接用Popen
print(
f'映像名称:{tasklist[0]} 会话名:{tasklist[2]} 会话#:{tasklist[3]} 内存使用:{tasklist[4]}',end="\n<------------------------------------------------------------------------->\n")
print('杀死进程指令taskkill /T /F /PID 进程PID')

FastAPI跨域

1
2
3
4
5
6
7
8
9
10
11
12
app = FastAPI()

origins = [
"*"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

素数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import random
from math import gcd


def is_prime(num: int) -> bool:
'''
判断是否素数
'''
if num < 2:
return False
for i in range(2, num):
if num % i == 0:
return False
return True


def rand_prime(a: int = 1, b: int = 100) -> int:
'''
在a和b的范围内随机输出一个素数
'''
while True:
num = random.randint(a, b)
if is_prime(num):
return num


def relatively_prime(a: int, b: int) -> bool:
'''
判断两数是否互质
'''
if gcd(a, b) == 1:
return True
else:
return False

MISC

Chrimium的一些坑

Openssl

1
openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -extensions v3_req -config openssl.cnf

VScode Jupyter

VScode里能用Jupyter,链接Jupyter服务器,不过是在本地的IPYNB 文件在服务器上运行。

废弃项目归档

Warframe高价值警报查看 #已废弃

5分钟检测一次,会返回节点名字和数据,判断方法是非I系入侵和奖励数量为1,非常简陋。

不过能设置已拥有(也就是不提示)物件啊什么的。

已经写成了QQ机器人,已上传到Github。

https://github.com/knight000/WF_valuableInvasion_CoolQ

异步是个好东西,可惜我不太会用….别再报错了啊!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import json
import ssl
import sys
import time
import urllib.request


def GetData():
# 从网站上获取数据,获取到的是字典
url = "https://api.warframestat.us/pc/invasions" # 直接获取入侵的数据
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/51.0.2704.63 Safari/537.36'}
req = urllib.request.Request(url=url, headers=headers)
res = urllib.request.urlopen(req)
data = json.loads(res.read())
return data


def GetZh(name):
# 用于翻译
str(name)
with open("C:\\VScode\\WFA_Lexicon\\WFA_Lexicon\\WF_Dict.json", "r", encoding="UTF-8") as f:
# 翻译文件来自https://github.com/Richasy/WFA_Lexicon
wfDictList = json.load(f)
for list1 in wfDictList:
wfDict = dict(list1)
if wfDict['en'] == name:
return wfDict['zh']
else:
continue


def CheckRepeat(id):
if id in RepeatID:
return True
else:
RepeatID.add(id)
return False


def UseInvasionData(invasions):
# 暂时只写了入侵的功能
# invasions = data["invasions"] #以后可能要用,就留着了
ReturnData = ""
for a in invasions:
dict1 = dict(a)
if CheckRepeat(dict1['id']):
# 去重
continue
if dict1['completion'] <= 0 or dict1['completion'] >= 100:
# RepeatID.remove(dict1['id']) # 去掉已过期的入侵,但是好像没必要就注释掉了
continue
if dict1['vsInfestation'] == True:
# 过滤掉I系相关的入侵,因为没有部件
continue
attacker = dict(dict1['attackerReward'])
attackerItem = attacker['countedItems']
attackerItem = dict(attackerItem[0])
defender = dict(dict1['defenderReward'])
defenderItem = defender['countedItems']
defenderItem = dict(defenderItem[0])
# 这里是已拥有的就不提示
if GetZh(attackerItem['type']) in Gotlist and GetZh(defenderItem['type']) in Gotlist:
continue
# if dict1['rewardTypes'] in highvalue:
if attackerItem['count'] == 1 or defenderItem['count'] == 1:
# 用奖励的数量来判断是不是武器部件
node = dict1['node']
completion = str(int(dict1['completion']))
ReturnData = ReturnData+"节点:"+node+",奖励是:[" + \
GetZh(attackerItem['type'])+']和[' + \
GetZh(defenderItem['type'])+"]当前进度:"+completion+"%\n"
if GetZh(attackerItem['type']) in Gotlist:
ReturnData = ReturnData + \
"其中["+GetZh(attackerItem['type'])+"]已拥有\n"
if GetZh(defenderItem['type']) in Gotlist:
ReturnData = ReturnData + \
"其中["+GetZh(defenderItem['type'])+"]已拥有\n"
return ReturnData


def SaveList(data):
# 预留以后拿来添加已获取物件的功能
f = open("data.list", "w")
for w in data:
f.write(w+"\n")
f.close()


def ReadList():
data = []
f = open("data.list", "r")
data = f.read()
data = data.splitlines()
return data


Gotlist = ReadList() # 这里在文件data.list里填写已获得的物品中文名字,注意不要打错,要和WF_Dict.json里的一样,用回车键分隔开
RepeatID = set() # 这里是记录已提醒的集合
while True:
check = UseInvasionData(GetData())
if check != "":
print("现在时间是:", time.asctime(time.localtime(time.time())))
print("发现高价值入侵:")
print(check)
time.sleep(300) # 五分钟运行一次

蓝奏云上传QQbot #已废弃

命令#upload

接收到命令的bot会调用LanZouCloud-API ,把已下载的文件夹里的全部文件上传,因为API的特性不会上传子文件夹,所以调用os.system,把成功上传的文件都剪切到同个目录的文件夹已上传里,因为用的LanZouCloud-API能自动解决超出文件大小限制和可上传文件的限制,所以用这个方法上传的话应该不会出什么问题,至于客户端那边就用 LanZouCloud-CMD 这个很成熟的工具解决。

说不定以后能让机器人下载>自动上传这样整,不过我是暂时不行的啦,现在瞎搞的机器人除了查wf和爬dxy之外就没什么自己写的功能了,上面说的功能还没开始写:D

由于各种原因,此项目已废弃。

备忘录 #已废弃

这是备忘录不是黑历史记录器啊喂!

因为没有酷Q Pro不能存图所以就没写图片保存

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from nonebot import on_command, CommandSession
import os


def SaveList(data, fileID):
fileID = 'memo\\'+str(fileID)+'.txt'
if os.path.exists('memo') == False:
os.mkdir('memo')
f = open(fileID, "a")
f.write(data+"\n")
f.close()


def ReadList(fileID):
fileID = 'memo\\'+str(fileID)+'.txt'
if os.path.exists('memo') == False:
os.mkdir('memo')
try:
f = open(fileID, "r")
except :
f = open(fileID, "w")
f.close()
return []
data = []
data = f.read()
data = data.splitlines()
f.close()
try:
removeNum = data.count('')
for i in range(removeNum):
data.remove('')
except:
pass
return data


def DelList(number, data, fileID):
del data[number]
fileID = 'memo\\'+str(fileID)+'.txt'
if os.path.exists('memo') == False:
os.mkdir('memo')
f = open(fileID, "w")
for w in data:
f.write(w+"\n")
f.close()


@on_command('SaveMemo', aliases=('memoadd', '添加备忘录'), only_to_me=False)
async def SaveMemo(session: CommandSession):
user_id = session.ctx['user_id']
session.state['memo'] = session.current_arg_text.strip()
memo = session.get('memo', prompt='请输入你要添加的备忘录')
try:
SaveList(memo, user_id)
except:
session.finish('储存失败')
session.finish('已储存至备忘录')


@on_command('ReadMemo', aliases=('memo', '读取备忘录', 'readmemo'), only_to_me=False)
async def ReadMemo(session: CommandSession):
user_id = session.ctx['user_id']
try:
user_name = session.ctx['sender']['card']
except:
user_name = session.ctx['sender']['nickname']
read = ReadList(user_id)
if read == []:
session.finish('无备忘录记录')
message = user_name+"的备忘录记录为:"
memonum = 0
for m in read:
message += "\n["+str(memonum)+"]"+m
memonum += 1
session.finish(message)


@on_command('DelMemo', aliases=('memodel', '删除备忘录', 'delmemo'), only_to_me=False)
async def DelMemo(session: CommandSession):
user_id = session.ctx['user_id']
session.state['delmemo'] = session.current_arg_text.strip()
delmemo = session.get('delmemo', prompt='请输入你要删除的备忘录序号')
try:
delmemo = int(delmemo)
except:
session.finish('请输入数字')
read = ReadList(user_id)
if delmemo > len(read) - 1:
session.finish('超出范围,删除失败')
else:
try:
DelList(delmemo, read, user_id)
except:
session.finish('删除失败')
session.finish('删除备忘录成功')


@on_command('HelpMemo', aliases=('memohelp','备忘录帮助'), only_to_me=False)
async def HelpMemo(session: CommandSession):
message = '#memoadd [备忘录内容]\n#添加备忘录 [备忘录内容] 添加备忘录\n#memo 读取备忘录 \n#readmemo 读取备忘录\n#memodel [序号]\n#删除备忘录 [序号]\n#delmemo [序号] 删除备忘录\n示例:\n#memoadd 这是一条备忘录\n#memodel 0'
session.finish(message)