Beispiel #1
0
def getDateFromInterface():
    #载入url
    urls = ConfigUtil.config2map('config/config_url.ini','URL')        
    headers = {'content-type': 'application/json'}
#    headers = {}
    data={}
    for url_key in urls.keys():
        resquest_data = json.dumps({"messageid": str(uuid.uuid1())})
        response = requests.post(url = urls[url_key], data = resquest_data, headers=headers, timeout=10)  
        data[url_key] = json.loads(response.text)
    return data
Beispiel #2
0
def sendMail(configFile, section, subject=0, context=0):

    config_mail = ConfigUtil.config2map(configFile, section)
    # 第三方 SMTP 服务
    mail_host = config_mail["mail.host"]  #设置服务器
    mail_user = config_mail["mail.user"]  #用户名
    mail_pass = config_mail["mail.pass"]  #口令

    sender = config_mail["mail.sender"]
    receivers = config_mail["mail.receivers"].split(
        ";")  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱
    if subject == 0:
        subject = config_mail["mail.subject"] + " —— " + time.strftime(
            "%Y-%m-%d %H:%M:%S", time.localtime())
    else:
        subject = subject + " —— " + time.strftime("%Y-%m-%d %H:%M:%S",
                                                   time.localtime())

    if context == 0:
        context = config_mail["mail.context"] + " —— " + time.strftime(
            "%Y-%m-%d %H:%M:%S", time.localtime())
    else:
        context = context + " —— " + time.strftime("%Y-%m-%d %H:%M:%S",
                                                   time.localtime())
    #创建一个带附件的实例
    message = MIMEMultipart('mixed')
    message['From'] = "系统邮件<%s>" % sender
    message['To'] = ";".join(receivers)
    message['Subject'] = subject
    #邮件正文内容
    message.attach(MIMEText(context, 'plain', 'utf-8'))

    try:
        smtpObj = smtplib.SMTP()
        smtpObj.connect(mail_host, 25)  # 25 为 SMTP 端口号
        smtpObj.login(mail_user, mail_pass)
        smtpObj.sendmail(sender, receivers, message.as_string())
        logging.info("邮件发送成功")
    except smtplib.SMTPException:
        logging.info("Error: 无法发送邮件")
Beispiel #3
0
def getDateFromInterface():
    #载入url
    urls = ConfigUtil.config2map('config/config_url.ini','URL')        
    headers = {'content-type': 'application/json'}
#    headers = {}
    data={}
    for url_key in urls.keys():
        resquest_data = json.dumps({"messageid": str(uuid.uuid1())})
        response = requests.post(url = urls[url_key], data = resquest_data, headers=headers, timeout=10)  
        data[url_key] = json.loads(response.text)
    return data

if __name__ == '__main__':

    config_mysql = ConfigUtil.config2map('config/config_mysql.ini','mysql-local')
    
    host = str(config_mysql["host"])
    user = str(config_mysql["user"])
    passwd = str(config_mysql["passwd"])
    port = int(config_mysql["port"])
    dbName = str(config_mysql["dbname"])
    tableName = str(config_mysql["tablename"])
    charset = str(config_mysql["charset"])
    

    
    try:
        db = pymysql.connect(host=host,
                             port=port,
                             user=user,