码迷,mamicode.com
首页 > 其他好文 > 详细

新写了,发送邮件的方法,以及怎么怎么去分页循环查数据处理

时间:2020-07-03 12:36:57      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:tp服务器   orm   filename   pre   art   zha   split   requests   ali   

import pymysql
import requests
import json
import  smtplib
import email.mime.multipart
import email.mime.text
from email.mime.application import MIMEApplication



def request_jiuyitong(uid,depid,doctorid):
    url="https://wsapitest2.91160.com/index.php?c=sch&a=getDoctor"
    data={
        "cid" : "100012848",
        "token" : "85422afb467e9456013a2a51d4dff702",
        "uid" : uid,
        "depid" : depid,
        "doctorid": doctorid
    }
    response=requests.request(method="POST",url=url,data=data,verify=False)
    state=str(json.loads(response.text).get("state"))
    msg=str(json.loads(response.text).get("msg"))
    return state,msg

def select_data(now):
    coon=pymysql.connect(host="10.1.22.107",port=3306,user="zhongtai",password="km5YFa1m9OWKJinw",database="cooperation_avatar",charset=utf8)
    cur=coon.cursor()
    sql="SELECT partnerhospitalid,partnerfacultyid,partnerdoctorid,doctorid FROM cooperation_avatar.`cooperations` WHERE partnersource=‘Jiuyitong‘ AND STATUS = ‘Valid‘ ORDER BY ctime DESC LIMIT {m},1000".format(m=now)
    cur.execute(sql)
    results=cur.fetchall()
    return results


def sendmail(content):
    ‘‘‘
    :param smtpHost: 域名
    :param sendAddr: 发送邮箱
    :param password: 邮箱密码
    :param QQ_ShouQuanMa: # qq邮箱需要开启的授权码
    :param recipientAddrs: 发送地址
    :param subject: 标题
    :param content: 内容
    :return: 无
    ‘‘‘




    QQ_ShouQuanMa = "eellpsozuujmbafa"  # qq邮箱需要开启授权
    CONTENT = str(content)  #邮箱发送的内容,需要转化成字符串
    # 设置邮件信息
    sendAddr = "1173829775@qq.com"  # 发件人邮箱
    password = QQ_ShouQuanMa  # 发件人邮箱密码(需要填写的授权码,不是密码)
    recipientAddrs = ["zhangzhenglai@haodf.com","540751032@qq.com"]  # 收件人邮箱
    subject = "合作挂号有问题的医生"  # 标题
    content = CONTENT  # 内容



    msg = email.mime.multipart.MIMEMultipart()
    msg[from] = sendAddr
    msg[to] = recipientAddrs
    msg[subject] = subject
    txt = email.mime.text.MIMEText(content, plain, utf-8)
    msg.attach(txt)

    # 附件
    # directory = "test3"  # 目录
    # file_name = "test.zip"  # 文件名
    # attachment_url = "C:\\test\\test2\\ " + directory + "\\ " + file_name
    # attachment_url = ‘‘.join(attachment_url.split())

    # 添加附件地址
    # part = MIMEApplication(open(r"" + attachment_url + "", ‘rb‘).read())
    # part.add_header(‘Content-Disposition‘, ‘attachment‘, filename="邮件中显示的文件名称.zip")  # 发送文件名称
    # msg.attach(part)

    smtp = smtplib.SMTP(smtp.qq.com, 25)  # SMTP服务器
    # 新浪邮箱:smtp.sina.com,新浪VIP:smtp.vip.sina.com,搜狐邮箱:smtp.sohu.com,126邮箱:smtp.126.com,139邮箱:smtp.139.com,163网易邮箱:smtp.163.com。
    smtp.login(sendAddr, password)
    text=smtp.sendmail(sendAddr, recipientAddrs, str(msg))
    print(text)
    print("发送成功!")


def find_problem_doctor():
    doctorlist = {}
    now = 0
    while True:
        results=select_data(now)
        if results is None:
            break
        for data in results:
            partnerhospitalid = data[0]
            partnerfacultyid = data[1]
            partnerdoctorid = data[2]
            doctorid = data[3]
            DOCTORID = "doctorId" + ":" + str(doctorid)
            now=now+1000
            text, msg = request_jiuyitong(partnerhospitalid, partnerfacultyid, partnerdoctorid)
            if text != "1":
                doctorlist[DOCTORID] = msg
    sendmail(doctorlist)


find_problem_doctor()

 

新写了,发送邮件的方法,以及怎么怎么去分页循环查数据处理

标签:tp服务器   orm   filename   pre   art   zha   split   requests   ali   

原文地址:https://www.cnblogs.com/zhenglai/p/13229470.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!