1短信平台
易码短信平台用于虚拟手机号注册账号,多用于爬虫进行注册;螺丝帽短信平台用于给指定手机号发短信,多用于开发进行认证个人信息
1.1螺丝帽
随机生成验证码并发送短信(用redis控制一个小时只能发送三次)
import io
import json
import time
import random
import requests
import redis
def gen_code(length=6):
"""生成指定长度的验证码"""
result = io.StringIO()
for _ in range(length):
result.write(str(random.randint(0, 9)))
return result.getvalue()
def send_messag_example(tel, code):
"""发送短信"""
resp = requests.post(
url='http://sms-api.luosimao.com/v1/send.json',
auth=('api', 'e67b65751337d36224b26074ceb8a421'),
data={
'mobile': tel,
'message': f'您的验证码为{code}。【铁壳测试】'
# 'message': f'猜猜我是谁。【铁壳测试】'
},
timeout=3,
verify=False
)
return json.loads(resp.content)
# 用redis控制一个小时只能发三次
def my_main():
tel = input('请输入手机号:')
cli = redis.StrictRedis(host='112.74.61.160', port=6379,
password='1qaz2wsx')
if not cli.exists(tel):
result = send_messag_example(tel, gen_code())
print(result)
if result['error'] == 0:
print('短信发送成功')
cli.set(tel, 1, ex=3600)
elif int(cli.get(tel)) < 3:
result = send_messag_example(tel, gen_code())
print(result)
if result['error'] == 0:
print('短信发送成功')
cli.incr(tel)
else:
print('请不要频繁发送短信验证码(1小时只能发送3次)')
my_main()
1.2易码
#获取手机号
def get_mobile():
# 获取手机号码
url = 'http://api.fxhyd.cn/UserInterface.aspx?action=getmobile&token=' + \
TOKEN + '&itemid=' + ITEMID + '&excludeno=' + EXCLUDENO
MOBILE1 = request.urlopen(request.Request(
url=url, headers=header_dict)).read().decode(encoding='utf-8')
if MOBILE1.split('|')[0] == 'success':
MOBILE = MOBILE1.split('|')[1]
print('获取号码是:\n' + MOBILE)
return MOBILE
else:
print('获取TOKEN错误,错误代码' + MOBILE1)
#获取短信
def get_sms_message(MOBILE):
# 获取短信,注意线程挂起5秒钟,每次取短信最少间隔5秒
WAIT = 100 # 接受短信时长60s
url = 'http://api.fxhyd.cn/UserInterface.aspx?action=getsms&token=' + \
TOKEN + '&itemid=' + ITEMID + '&mobile=' + MOBILE + '&release=1'
text1 = request.urlopen(request.Request(
url=url, headers=header_dict)).read().decode(encoding='utf-8')
TIME1 = time.time()
TIME2 = time.time()
ROUND = 1
while (TIME2 - TIME1) < WAIT and not text1.split('|')[0] == "success":
time.sleep(5)
text1 = request.urlopen(request.Request(
url=url, headers=header_dict)).read().decode(encoding='utf-8')
TIME2 = time.time()
ROUND = ROUND + 1
ROUND = str(ROUND)
if text1.split('|')[0] == "success":
text = text1.split('|')[1]
TIME = str(round(TIME2 - TIME1, 1))
print('短信内容是' + text + '\n耗费时长' + TIME + 's,循环数是' + ROUND)
# 提取短信内容中的数字验证码
pat = "验证码(.*?),"
IC = 0
IC = re.findall(pat, text)
if IC:
print("验证码是:\n" + IC[0])
return IC[0]
else:
print('获取短信超时,错误代码是' + text1 + ',循环数是' + ROUND)
2文件压缩
import zipfile
import tkinter
import tkinter.filedialog
import os
import tkinter.messagebox
zipfilename = []
def addfile():
#全局化变量
global zipfilename
#弹出文件选框
files = tkinter.filedialog.askopenfilenames(title = '请选择需要压缩的文件')
#将选择的文件加入列表中
zipfilename += list(files)
#将信息组成字符串书写
filesstr = '\n'.join(zipfilename)
print(filesstr)
def zip_file():
addfile() # 调用加入需要压缩的文件的函数
path = './text.zip' # 压缩文件保存路径及名字
#打开或者创建压缩文件
zp = zipfile.ZipFile(path,'w')
#添加文件
for filename in zipfilename:
zp.write(filename,os.path.basename(filename))
#关闭压缩文件
zp.close()
#判断压缩文件是否创建成功
if os.path.exists(path):
tkinter.messagebox.showinfo(title = '信息',message = '文件压缩成功:' + path ) # tkinter界面弹框
else:
tkinter.messagebox.showerror(title = '错误',message = '压缩文件失败!')
zip_file()
3利用程序将多个压缩包中指定文件统一解压至一个文件夹
import os, tarfile
def get_zip_file():
file_path = '/home/glzt/桌面/滴滴数据'
file_list = os.listdir(file_path)
for file in file_list:
# 只对gz结尾的进行解压,否则会对文件夹也进行操作,就会报错
if file.endswith('gz'):
file = file_path + '/' + file
untar_gz(file)
# file_path = '/home/glzt/桌面/滴滴数据/f2cef02239f346088d96758888072be1.tar.gz'
def untar_gz_all(file_path):
# 全部解压
tar = tarfile.open(file_path)
names = tar.getnames()
if os.path.isdir(file_path+"_files"):
pass
else:
os.mkdir(file_path+"_files/")
for name in names:
tar.extract(name, file_path+"_files/")
tar.close()
def untar_gz(file_path):
# 解压以order开头的文件
tar = tarfile.open(file_path)
names = tar.getnames()
for name in names:
if name.startswith('order'):
tar.extract(name, '/home/glzt/桌面/滴滴数据/file/')
tar.close()
网友评论