①app.py
:
#导入模块
from requests import post
from easygui import msgbox,multenterbox,buttonbox,enterbox
#声明变量
title = '网址缩短器'
def output(types,name,custom):
if types == 'create':
url = 'https://dwz.mn/create.aspx'
params = {'url' : name,'https' : '1','alias' : custom}
response = post(url,params = params)
content = response.json()
if content['status'] == 0:
msgbox('原网址:%s\n短网址:%s\n' % (content['longurl'],content['tinyurl']),title)
else:
msgbox('错误!\n原因:%s' % content['err_msg'],title)
elif types == 'query':
url = 'https://dwz.mn/query.aspx'
params = {'tinyurl' : name}
response = post(url,params = params)
content = response.json()
if content['status'] == 0:
msgbox('短网址:%s\n原网址:%s\n' % (name,content['longurl']),title)
else:
msgbox('错误!\n原因:%s' % content['err_msg'],title)
def main():
choose = buttonbox('请选择您需要的短网址服务:',title,('新建','还原'))
if choose == '新建':
text = multenterbox('请填写下面的信息:',title,('长网址:','自定义后缀:'))
output(types = 'create',name = text[0],custom = text[1])
elif choose == '还原':
text = enterbox('请输入短网址:',title)
output(types = 'query',name = text,custom = '')
else:
exit()
if __name__ == '__main__':
main()
②依赖包:
easygui==0.98.1
requests==2.23.0
requests-oauthlib==1.3.0