Update pkg.py

添加aur包过期提示,优化部分代码
This commit is contained in:
xmengnet 2021-08-18 18:06:31 +08:00 committed by GitHub
parent b7b0c8c37c
commit 56f306c82b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,12 +21,20 @@ class Ans(StdAns):
repo = '&repo=' + self.parms[2].capitalize() repo = '&repo=' + self.parms[2].capitalize()
except: except:
print('repo empty') print('repo empty')
def timeTrans(value):
temp = time.localtime(int(value))
timeValue = time.strftime("%Y-%m-%d %H:%M:%S", temp)
return timeValue[:16]
req = requests.get( req = requests.get(
url='https://archlinux.org/packages/search/json/?name=' + self.parms[1] + repo).json() url='https://archlinux.org/packages/search/json/?name=' + self.parms[1] + repo).json()
if not req['results']: if not req['results']:
req = requests.get(url='https://aur.archlinux.org/rpc/?v=5&type=info&arg=' + self.parms[1]).json() req = requests.get(
url='https://aur.tuna.tsinghua.edu.cn/rpc/?v=5&type=info&arg=' + self.parms[1]).json()
if req['resultcount'] == 0: if req['resultcount'] == 0:
req = requests.get(url='https://aur.archlinux.org/rpc/?v=5&type=search&arg=' + self.parms[1]).json() req = requests.get(
url='https://aur.tuna.tsinghua.edu.cn/rpc/?v=5&type=search&arg=' + self.parms[1]).json()
# print(req) # print(req)
if req['resultcount'] > 0: if req['resultcount'] > 0:
name = '包名:' + req['results'][0]['Name'] name = '包名:' + req['results'][0]['Name']
@ -35,16 +43,18 @@ class Ans(StdAns):
description = '描述:' + req['results'][0]['Description'] description = '描述:' + req['results'][0]['Description']
maintainer = '维护:' + str(req['results'][0]['Maintainer']) maintainer = '维护:' + str(req['results'][0]['Maintainer'])
numvotes = '投票:' + str(req['results'][0]['NumVotes']) numvotes = '投票:' + str(req['results'][0]['NumVotes'])
updatetime = req['results'][0]['LastModified'] updatetime = '更新日期:' + timeTrans(req['results'][0]['LastModified'])
updatetime = time.localtime(int(updatetime)) outofdate = req['results'][0]['OutOfDate']
updatetime = time.strftime("%Y-%m-%d %H:%M:%S", updatetime) if outofdate is not None:
outofdate=timeTrans(outofdate)
updatetime = updatetime + '\n过期日期:' + outofdate
url = req['results'][0]['URL'] url = req['results'][0]['URL']
if url is None: if url is None:
url = '链接None' url = '链接None'
else: else:
url = '链接:' + url url = '链接:' + url
msg = '仓库AUR\n' + name + '\n' + version + '\n' + description + '\n' + maintainer \ msg = '仓库AUR\n' + name + '\n' + version + '\n' + description + '\n' + maintainer \
+ '\n' + numvotes + '\n更新日期:' + updatetime + '\n' + url + '\n' + numvotes + '\n' + updatetime + '\n' + url
return msg return msg
else: else:
repo = req['results'][0]['repo'] repo = req['results'][0]['repo']