import traceback
import requests
import logging
import os
from mysql_factory.connection import Conn_Db
from mysql_factory.dau import Data_utils
from Git_factory.dau import Data_Handle
from Git_factory.connection import Conn_Git
from pprint import pprint
from utils import Config_Utils
from suds.client import Client
b = os.path.dirname(__file__)
git_sql_cfg_file = os.path.join(b,'E:/xxxx/xxxx/xxx/sql.yaml')
git_sql_cfg = Config_Utils.read_config(git_sql_cfg_file)
department_name=input("请输入需要查询的部门: ")
git_sql_week__cfg = git_sql_cfg['sql_email'].format(department_name)
git_sql_history_cfg = git_sql_cfg['sql_all_email'].format(department_name)
pool,conn = Conn_Db.get_connection_pool("test_server")
cursor = conn.cursor()
cursor.execute(git_sql_week__cfg )
results=cursor.fetchall()
ret = []
for i in results:
temp = {
'date_range':i[0],'USER':i[1],'USER_ID':i[2],'PROJRCT':i[3],'GROUP':i[4],'pushed to':i[5],'pushed new':i[6],'created':i[7],'deleted':i[8],'joined':i[9],'left':i[10],'total':i[11]}
ret.append(temp)
cursor.execute(git_sql_history_cfg)
results_0=cursor.fetchall()
ret_all = []
for i in results_0:
temp_all = {
'DATE':i[0],'USER':i[1],'USER_ID':i[2],'PROJRCT':i[3],'GROUP':i[4],'pushed to':i[5],'pushed new':i[6],'created':i[7],'deleted':i[8],'joined':i[9],'left':i[10],'total':i[11]}
ret_all.append(temp_all)
week_head =\
"""
xxxxx点检清单
xxxxx点检清单
date_range |
USER |
USER_ID |
PROJRCT |
GROUP |
pushed to |
pushed new |
created |
deleted |
joined |
left |
total |
"""
week_tbody=""
for i in ret:
week_thbody=\
"""
{0} |
{1} |
{2} |
{3} |
{4} |
{5} |
{6} |
{7} |
{8} |
{9} |
{10} |
{11} |
""".format(i['date_range'],i['USER'],i['USER_ID'],i['PROJRCT'],i['GROUP'], i['pushed to'] , i['pushed new'] ,i['created'] , i['deleted'] , i['joined'] ,i['left'],i['total'] )
week_tbody +=week_thbody
history_head=\
"""
xxxxx历史点检清单
gitlab历史点检清单
DATE |
USER |
USER_ID |
PROJRCT |
GROUP |
pushed to |
pushed new |
created |
deleted |
joined |
left |
total |
"""
history_tbody=""
for i in ret_all:
history_thbody=\
"""
{0} |
{1} |
{2} |
{3} |
{4} |
{5} |
{6} |
{7} |
{8} |
{9} |
{10} |
{11} |
""".format(i['DATE'],i['USER'],i['USER_ID'],i['PROJRCT'],i['GROUP'], i['pushed to'] , i['pushed new'] ,i['created'] , i['deleted'] , i['joined'] ,i['left'],i['total'] )
history_tbody +=history_thbody
html_msg = "" + week_head +""+ week_tbody+"" + "
"+"" + history_head +""+ history_tbody+"" + "
"
url = 'http://xxxxxx.com/Messaging.asmx?wsdl'
client=Client(url)
header={
'UserId':'xxxx','Password':'xxxx'}
client.set_options(soapheaders=[header,])
TO = '[email protected]'
CC = ''
Subject = 'xxxxxxxx'
Body = html_msg
Smtpld = ''
SmtpPassword = ''
SmtpAddress = '[email protected]'
NoteAddress = '[email protected]'
NotesPassword = 'xxxxxx'
res = client.service.SendGroupMails(TO,CC,Subject,Body,Smtpld,SmtpPassword,SmtpAddress,NoteAddress,NotesPassword)
if res[0][0].find(",1,") !=-1:
print('连接成功')
else:
print('连接失败')
发送email成功后得到的结果如下所示:
