Exemplo n.º 1
0
def _add_image_of_provision(msg):
    project_name = "provision"

    root_path = "/tmp/"
    path = root_path + project_name + ".png"
    try:
        fp = open(path, 'rb')
        msgImgage = MIMEImage(fp.read())
        fp.close()
        msgImgage.add_header('Content-ID', '<image_%s>' % project_name)
        msgImgage[
            "Content-Disposition"] = 'attachment;filename = %s.png' % project_name
        msg.attach(msgImgage)
    except IOError:
        logger.error("File %s not exits" % path)
    except Exception, e:
        logger.error("exception accured in add image![%s]" % e)
Exemplo n.º 2
0
def send_email(subject, body, async=True, to_list=MAIL_TO, is_picture=False, is_api=True):
    try:
        if async:
            t = Process(target=send_email,
                        args=(subject, body, False, to_list, is_picture, is_api))
            t.daemon = False
            t.start()
            logger.info(
                "start a process to send email, subject[%s], tolist[%s]" % (subject, to_list))
        else:
            msg = _prepare_msg(subject, body, mail_to=to_list,
                               is_picture=is_picture, is_api=is_api)
            smtp = _prepare_smtp()
            smtp.sendmail(MAIL_FROM, to_list, msg.as_string())
            smtp.quit()
    except Exception, e:
        logger.error("exception accured in send email![%s]" % e)
        pass

html_str = '<html><head></head><body><h1>测试 again test mail</h1>\
            <br /><img src="cid:image1" /><img src="cid:image2"></body></html>'

if __name__ == "__main__":
    # send_email("[subject] Test Email", html_str, filepath=filepath,True)
    send_email("[subject] Test Email", html_str)
    while True:
        time.sleep(5)
        print "Done"
        break
Exemplo n.º 3
0
        device_count = 0
        user_ids = _push_db_conn.query_sql(query_userids)
        try:
            for user_id in user_ids:
                device_count += get_user_device_count(user_id[0])
        except Exception, e:
            print e
            pass
        current_table["device_count"] = device_count
        try:
            if user_count > 0:
                current_table["avg_device_count"] = round(
                    float(device_count) / user_count, 3)
        except Exception, e:
            logger.error("wrong in avg_device_count %s" % e)
            print e
        current_table["active_user_count"] = get_push_active_count(date)
        current_table["offline_push_count"] = get_offline_push_count(date)


def get_push_data_by_month(date):
    temp_day = date
    global reuslt_table
    for i in range(7):
        get_push_statistics(temp_day)
        temp_day -= timedelta(1)
    items = result_table.items()
    items.sort(reverse=True)
    return items