Ejemplo n.º 1
0
def insert_data():
    ins = InsertData()
    ins.delte_data_by_collect_date(g_date)

    fileList = os.listdir('.')
    outList = list()
    attList = list()

    for file in fileList:
        if file.endswith(".csv") and file.startswith(g_date):
            attList.append(file)
            pFile = open(file, 'r')
            contentList = pFile.readlines()
            for item in contentList:
                if '数据来源' in item:
                    continue
                tmpList = item.strip().split(',')
                outList.append([
                    tmpList[0], tmpList[1], tmpList[2], tmpList[3], tmpList[4],
                    tmpList[5]
                ])

    ins.insert_data(outList)
    ins.close_db()

    #发送邮件
    mail_sender = MailSender()
    mail_list = ['*****@*****.**']  #收件人(列表)
    mail_sender.send(mail_list, "每日手机价格数据自动推送", attList)
Ejemplo n.º 2
0
def check_mail():
    try:
        fetch_mail()
    except Exception as e:
        print("log error")
        print(e)
        MailSender.send("*****@*****.**", 'ERROR', "log error\n" + str(e),
                        False)
Ejemplo n.º 3
0
def daily_job():
    DBManager.update_today()
    content = InfoHandler.pack_daily_content()
    receivers = DBManager.get_auditors()
    MailSender.send(receivers, 'Daily LeetCode Notice', content, True)
    DBManager.update_yestoday()
    print("daily job done")
    return
Ejemplo n.º 4
0
def send_mail():

    fileList = os.listdir('.')
    attList = list()

    for file in fileList:
        if file.endswith(".csv") and file.startswith(g_date):
            attList.append(file)

    #发送邮件
    mail_sender = MailSender()
    mail_list = ['*****@*****.**']  #收件人(列表)
    mail_sender.send(mail_list, '每周美的价格数据自动推送', attList)
Ejemplo n.º 5
0
    def send_mail(self, task_info, f_nfs_path):
        """Send response mail.
        """
        f_task_id = task_info["f_task_id"]
        f_task_type = task_info["f_task_type"]
        f_task_desc = task_info["f_task_desc"]
        f_task_author = task_info["f_task_author"]
        result_desc = task_info["f_result_schema"]
        bcc = "xiumingzhu;tobywang;karlwu;yvanwang;acailiu;"
        # cc = "acailiu;"
        if f_task_type == "video_accu_reach":
            f_nfs_path_src = os.path.dirname(f_nfs_path) + "/src_" + os.path.basename(f_nfs_path)
            os.rename(f_nfs_path, f_nfs_path_src)
            make_excel.make_add_uv_excel(result_desc, f_nfs_path_src, f_nfs_path)
        elif f_task_type == "video_freq":
            f_nfs_path_src = os.path.dirname(f_nfs_path) + "/src_" + os.path.basename(f_nfs_path)
            os.rename(f_nfs_path, f_nfs_path_src)
            make_excel.make_freq_excel(result_desc, f_nfs_path_src, f_nfs_path)
        elif f_task_type == "video_puv":
            f_nfs_path_src = os.path.dirname(f_nfs_path) + "/src_" + os.path.basename(f_nfs_path)
            os.rename(f_nfs_path, f_nfs_path_src)
            make_excel.make_puv_excel(result_desc, f_nfs_path_src, f_nfs_path)

        f_nfs_path = "http://10.137.129.174/result/walrus_%d.csv" % f_task_id
        if f_task_author is not None:
            to = f_task_author
        else:
            to = "walrus"
            logger.error("Task %d forgot his task submitter!" % f_task_id)
        subject = "海象计算任务反馈邮件"
        body = ('''<html>
                                    <head>
                                    <style type="text/css">
                                    body
                                      {
                                      font-family:"Microsoft YaHei";
                                      width:100%%;
                                      border-collapse:collapse;
                                      }
                                    </style>
                                    </head><body>'''
                '''Dear %(f_task_author)s,<br><br>'''
                ''' 您定制的海象任务,task_id: %(f_task_id)d [%(f_task_type)s] [%(f_task_desc)s] 已经顺利执行完成。<br><br>查看结果,请点击链接:<a href="%(f_nfs_path)s">结果文件</a>'''
                '''<br><br>祝好!<br>Walrus 项目组</body></html>'''
                % {"f_task_id": f_task_id,
                   "f_task_type": f_task_type,
                   "f_task_desc": f_task_desc,
                   "f_task_author": f_task_author,
                   "f_nfs_path": f_nfs_path})
        # MailSender.send_mail(to, subject, body, htmlFlag=True, cc=cc, attachments=f_nfs_path)
        MailSender.send_mail(to, subject, body, htmlFlag=True, bcc=bcc)
Ejemplo n.º 6
0
def getConn():
    '''获取数据库连接'''
    global error_count
    try:
        conn = mp.getConn()
        error_count = 0
        return conn
    except Exception: #从连接池获取连接失败。 #发报警邮件
        error_count += 1
        if error_count % 1000 == 1: #每隔100次发个邮件
            subject = 'server:%s connects MySQLdb Failed!'%config.SERVER_ID
            body = 'error count:%d' % error_count
            MailSender.sendmail(subject, body)
        return None
Ejemplo n.º 7
0
def getConn():
    '''获取数据库连接'''
    global error_count
    try:
        conn = mp.getConn()
        error_count = 0
        return conn
    except Exception:  #从连接池获取连接失败。 #发报警邮件
        error_count += 1
        if error_count % 1000 == 1:  #每隔100次发个邮件
            subject = 'server:%s connects MySQLdb Failed!' % config.SERVER_ID
            body = 'error count:%d' % error_count
            MailSender.sendmail(subject, body)
        return None
Ejemplo n.º 8
0
 def setupHandlers(self):
     try:
         self.mailBuffer = MailSender.MailSender()
     except:
         QtGui.QMessageBox.information(
             self, "Warning",
             "Could not enstablish SMTP connection. Check your port routing."
         )
         time.sleep(1.5)
         QtGui.qApp.quit()
     self.checkBox_2.setChecked(True)
     self.settings = self.initLines()
     self.mailingList = self.updateMailingList()
     self.agentsData = sorted(self.getLists(), key=lambda tup: tup[3])
     self.filtered = []
     displayAll = lambda: self.displayAgents(self.agentsData)
     sendMail = lambda: self.sendMessage(self.treeWidget.selectedItems())
     self.retranslateUi(MainWindow)
     QtCore.QMetaObject.connectSlotsByName(MainWindow)
     self.pushButton_8.clicked.connect(displayAll)
     self.pushButton_3.clicked.connect(sendMail)
     self.lineEdit.textChanged.connect(self.filterSort)  # type
     self.lineEdit_2.textChanged.connect(self.filterSort)  # days
     self.lineEdit_3.textChanged.connect(self.filterSort)  # days
     self.lineEdit_4.textChanged.connect(self.filterSort)  # date
     self.lineEdit_5.textChanged.connect(self.filterSort)  # job
     self.lineEdit_6.textChanged.connect(self.filterSort)  # name
     self.pushButton_7.clicked.connect(self.sendAllMessages)
     self.checkBox.stateChanged.connect(self.filterSort)
     self.commandLinkButton.clicked.connect(self.openExcelFile)
     self.actionExit.triggered.connect(app.quit)
     self.checkBox_2.stateChanged.connect(self.filterSort)
     self.filterSort(31)
Ejemplo n.º 9
0
 def ConfirmAssign(mailboxList, client):
     conn = sqlite3.connect('Emailbox.db')
     cursor = conn.cursor()
     idList = list()
     #set mailbox inused
     for mailbox in mailboxList:
         idList.append(mailbox.id)
         cursor.execute("UPDATE MAILBOXES SET INUSED=1 WHERE ID=?",
                        (mailbox.id, ))
     #random password
     pwd = ''.join(random.choice(string.digits) for _ in range(8))
     #get pwd hash
     hashPwd = MailboxRepository.PwdHashing(pwd)
     insertData = (
         hashPwd,
         json.dumps(idList),
         client.id,
     )
     #bind the mailbox inused, and client id, password
     cursor.execute(
         "INSERT INTO MAILBOX_BINDING VALUES(NULL,?,?,?,CURRENT_TIMESTAMP,0)",
         insertData)
     sendEmailThread = MailSender.SendPasswordMailThread(
         client.email_address, pwd)
     sendEmailThread.start()
     conn.commit()
     conn.close()
Ejemplo n.º 10
0
    def ResendPassword():
        conn = sqlite3.connect('Emailbox.db')
        cursor = conn.cursor()
        #get all unfinish mailbox_binding
        cursor.execute(
            '''SELECT CLIENT_ID, (strftime('%s','now') - strftime('%s', LAST_REMIND_TIME))
                        FROM MAILBOX_BINDING 
                        WHERE FINISH=0
                        ''')
        orders = cursor.fetchall()
        if orders is not None:
            for order in orders:
                client_id = order[0]
                last_remind = order[1]
                if last_remind > 60:
                    #change password
                    pwd = ''.join(
                        random.choice(string.digits) for _ in range(8))
                    pwdHashing = MailboxRepository.PwdHashing(pwd)
                    cursor.execute(
                        "UPDATE MAILBOX_BINDING SET PWD=?, LAST_REMIND_TIME=CURRENT_TIMESTAMP",
                        (pwdHashing, ))
                    #send password to client
                    cursor.execute(
                        "SELECT EMAIL_ADDRESS FROM CLIENTS WHERE ID=?",
                        (client_id, ))
                    client_email_address = cursor.fetchone()
                    sendMailThread = MailSender.SendPasswordMailThread(
                        client_email_address[0], pwd)
                    sendMailThread.start()
                    sendMailThread.join()

        conn.commit()
        conn.close()
Ejemplo n.º 11
0
def log_trick(device_id, monkey_log, sender, pwd, receivers, anr_receivers,
              subject, logfile, browser, device, version, keyword):
    FunCom.log('start log analyze')

    # todo
    # exception_handle(device_id)
    if FunCom.exists(monkey_log):
        f = open(monkey_log)
        lines = f.read()
        exception = "Exception"
        crash = "CRASH"
        anr = "ANR"
        native_crash = 'Short Msg: Native crash'
        not_running = 'is your activity running'

        focus_on = "Bitmap"
        logcat_to_file = focus_on in lines
        if exception in lines or crash in lines:
            crash_result = lines[lines.index(crash) - 200:]
            crash_result = crash_result.replace('\n', '<br>')
            exception_handle(device_id, logcat_to_file)
            if check_key_word(crash_result, keyword):
                Sender.sendException(crash_result, sender, pwd, receivers,
                                     subject, logfile, browser, device,
                                     version)
                FunCom.log("monkey finished with exception")
            else:
                FunCom.log('monkey finished with system exception\n')
                FunCom.log('<<<<<<<<<<<<<<<<<<<<<\n' + crash_result)
        elif anr in lines:
            FunCom.log("monkey finished with anr")
            FunCom.log(lines[lines.index(anr):lines.index(anr) + 10000])
            crash_result = lines[lines.index(anr):lines.index(anr) + 200]
            crash_result = crash_result.replace('\n', '<br>')
            exception_handle(device_id, logcat_to_file)
            Sender.sendException(crash_result, sender, pwd, anr_receivers,
                                 subject.replace('Crash', 'ANR'), logfile,
                                 browser, device, version)
        elif native_crash in lines:
            exception_handle(device_id, logcat_to_file)
            FunCom.log('monkey finished with native crash')
        elif not_running in lines:
            FunCom.log('monkey finished with activity not running')

        f.close()
        FunCom.log('>>> monkey finished...\n\n')
Ejemplo n.º 12
0
def fetch_mail():
    # 输入邮件地址, 口令和POP3服务器地址:
    mail_user = "******"
    mail_pass = "******"
    conn = poplib.POP3_SSL('pop.qq.com', 995)
    # 可以打开或关闭调试信息:
    conn.set_debuglevel(0)
    conn.user(mail_user)
    conn.pass_(mail_pass)
    # 获取邮件统计信息,邮件数 总大小
    message_num, total_size = conn.stat()
    if message_num == 0:
        print("no mail found")
        return
    # resp保存服务器的响应码
    # mails列表保存每封邮件的编号、大小
    # resp, mails, octets = conn.list()
    for i in range(message_num):
        # resp保存服务器的响应码, data保存该邮件的内容
        resp, data, octets = conn.retr(i + 1)
        # 将字符串内容解析成邮件
        msg_data = b'\r\n'.join(data)
        msg = BytesParser(policy=default).parsebytes(msg_data)
        sender = msg['from'].addresses[0].username + '@' + msg[
            'from'].addresses[0].domain
        subject = msg['subject']
        print("new mail (" + sender + ", " + subject + ")")
        try:
            handle_mail(sender, subject)
        except Exception as e:
            print("handle mail error")
            print(e)
            MailSender.send("*****@*****.**", 'ERROR',
                            "handle mail error\n" + str(e), False)
    for i in range(message_num):
        conn.dele(i + 1)
    conn.quit()
    return
Ejemplo n.º 13
0
def RemovalTask():
    DirPath = str(sys.argv[1])
    Minitues = int(sys.argv[2])
    MailTo = str(sys.argv[3])
    rList = FileHelper.DuplicateRemover(DirPath)
    LogTime = str(time.ctime())
    LogFileName = str("Duplicates_Removed_at_%s.log" % (LogTime))
    if (FileHelper.GenreateLogFile(rList, LogFileName, LogTime)):
        print('Success: Log file generated.')
        MailSender.SendMail(LogFileName, MailTo)
    else:
        print(
            "Failure: Unable to create logfile.\nPlease enter valid directory path and try again!"
        )
Ejemplo n.º 14
0
 def sendMessageHelper(self, item):
     agent = item[0]
     name = agent.text(0)
     date = agent.text(2)
     delta = agent.text(3)
     type = agent.text(4)
     if type.__contains__("Annual"):
         type += " Review"
     if not self.mailBuffer:
         self.mailBuffer = MailSender.MailSender()
     message = "Agent " + name + " is due for his/hers " + type + " in " + delta + " days." \
                                                                                   "The review is scheduled for " + date
     for i in self.mailingList:
         self.mailBuffer.sendEmail(name, delta, str(message), i)
Ejemplo n.º 15
0
def job():
    try:
        if ITSKenpoLogin.login(logininfo.kigou, logininfo.bangou,
                               logininfo.password) == True:
            time.sleep(random.randint(3, 10))
            ITSUpdateMission.update(ITSKenpoLogin.session,
                                    ITSKenpoLogin._token)
            time.sleep(random.randint(5, 10))
            ITSVitalInput.update(ITSKenpoLogin.session, ITSKenpoLogin._token)
            time.sleep(random.randint(5, 10))

            if globals()['premonth'] != datetime.today().month:
                ITSView.view(ITSKenpoLogin.session, ITSKenpoLogin._token,
                             logininfo.securitycode)
                globals()['premonth'] = datetime.today().month
                time.sleep(random.randint(5, 10))

            ITSKenpoLogin.logout()
    except Exception as ex:
        if len(logininfo.mailaddress) != 0 and len(logininfo.mailaddress) != 0:
            MailSender.send(logininfo.mailaddress, logininfo.mailpassword,
                            str(ex))

        logging.error(str(ex))
Ejemplo n.º 16
0
    def __init__(self, dbName=None):
        QRunnable.__init__(self)
        if (dbName):
            self.db=dbName
        else:
            self.db = "BoLa"
        self.projectPath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

        self.categories  = {"ALTA": 1, "MEDIA": 1, "BAJA": 1}
        self.categoriesPath = self.projectPath+"/Categories"
        self.setDb(self.db)
        if not os.path.exists(self.categoriesPath):
            os.makedirs(self.categoriesPath)
        self.signals = HaploSignal()
        self.option="compare"
        self.newDb=None
        self.mailsvc = Mail.MailSender()
Ejemplo n.º 17
0
def DuplicateFileRemoval(path, mid, starttime):
    dire = os.path.abspath("MADS")
    if os.path.isdir(dire) == False:
        os.makedirs(dire)
    filename = os.path.join(dire, "Logfile%s.txt" % time.time())
    fobj = open(filename, 'w')
    dup = {}
    for folder, subfolder, files in os.walk(path):
        for fname in files:
            fname = os.path.join(folder, fname)
            checksum = hashfile(fname)
            if checksum in dup:
                dup[checksum].append(fname)
            else:
                dup[checksum] = [fname]
    result = list(filter(lambda x: len(x) > 1, dup.values()))
    fcnt = 0
    icnt = 0
    dfile = 0
    if len(result) == 0:
        fobj.write("No Duplicate files")
    else:
        fobj.write("Duplicate files are :" + "\n")
        for s in result:
            icnt = 0
            for f in s:
                fcnt += 1
                icnt += 1
                if icnt > 1:
                    dfile += 1
                    fobj.write(f + "\n\n")
                    os.remove(f)
    fobj.close()
    body = """Hello ,Starting time of scanning: %s. Total number of files scanned: %s. Total number of duplicate files found: %s """ % (
        starttime, fcnt, dfile)

    if is_connected():
        MailSender(mid, filename, body, starttime)

    else:
        print("Internet connection is off")
Ejemplo n.º 18
0
def event_trigger(event):
    """
    event trigger function. trigger event information, judge whether
    is happened.
    trigger time interval get from event.time_trigger, global variable
    time_trigger or 60 seconds.
    :param event: object init from class EventBase
    :return: None
    """
    while True:
        event.pre_step()
        try:
            is_happened = event.is_event_happened()
            if is_happened:
                event.create_email_msg()
                if dry_run is False:
                    ms = MailSender.MailSender()
                    ms.mail_send(event.msg, event.user_to, event.user_cc,
                                 event.attachment)
        except Exception as e:
            logger.error("error happened when trigger event[%s], error %s.",
                         event.name, e)
            is_happened = True
            event.err_msg = e
        finally:
            event.post_step()
        if is_happened:
            if event.err_msg == "":
                logger.info("Event[%s] trigger.", event.name)
            if event.err_msg != "" or not event.re_trigger:
                return
        if event.time_interval is not None:
            time.sleep(event.time_interval)
        elif time_interval is not None:
            time.sleep(time_interval)
        else:
            time.sleep(60)
Ejemplo n.º 19
0
def ProcessLog(ListofFile,
               scannfile_count,
               Starting_time,
               mailId,
               path="Marvellous"):
    if not os.path.exists(path):
        try:
            os.mkdir(path)
        except:
            pass
    filename = os.path.join(path, "logfile%s.log" % (time.time()))
    D_count = 0

    line = "-" * 80
    fobj = open(filename, 'w')

    fobj.write(line + "\n")
    fobj.write("Marvellous names of duplicate files\n")
    fobj.write(line + "\n")
    for outer in ListofFile:
        icnt = 0
        for inner in outer:
            icnt += 1
            if icnt >= 2:
                D_count += 1
                fobj.write(inner + "\n")
                os.remove(inner)

    #print("Total Duplicate files ",D_count);
    if D_count == 0:
        str = "NOt found duplicate file in Directory"
        fobj.write(str + "\n")
    T = time.ctime()
    fobj.write("\nProcessing time:" + T)
    fobj.close()
    MailSender.Send(filename, mailId, scannfile_count, D_count, Starting_time)
Ejemplo n.º 20
0
def handle_mail(sender, subject):
    elements = str.split(subject, ' ')
    if elements[0] not in ["DY", "TD", "CX"]:
        return
    print("handle mail - " + subject + " from " + sender)
    if elements[0] == "DY":
        if len(elements) == 2:
            DBManager.logon_user(elements[1], sender, 0, 0)
        elif len(elements) == 3 and elements[2] == "cn":
            DBManager.logon_user(elements[1], sender, 0, 1)
        else:
            DBManager.logon_user(elements[0], sender, 1)
        MailSender.send(sender, 'Reply to DY', 'register successfully', False)
    elif elements[0] == "TD":
        DBManager.logoff_user(sender)
        MailSender.send(sender, 'Reply to TD', 'quit successfully', False)
    elif elements[0] == "CX":
        DBManager.update_today()
        content = InfoHandler.pack_daily_content()
        MailSender.send(sender, 'Reply to CX', content, True)
    return
Ejemplo n.º 21
0
    def send_warn_mail(self, task_info):
        """Send warning mail.
        """
        f_task_id = task_info["f_task_id"]
        f_task_type = task_info["f_task_type"]
        f_status = task_info["f_status"]
        f_status_desc = task_info["f_status_desc"]
        f_task_author = task_info["f_task_author"]
        to = "xiumingzhu;tobywang;karlwu;yvanwang;acailiu;"
        if f_task_author is not None:
            cc = f_task_author
        else:
            cc = ""
        subject = "海象计算任务执行失败告警"
        d_status_info = {
            1: "任务校验失败",
            5: "任务计算失败"
        }
        f_status = d_status_info[f_status]
        body = ('''<html>
                                	<head>
                                	<style type="text/css">
                                	#warn_mail
                                	  {
                                	  font-family:"Microsoft YaHei";
                                	  width:100%%;
                                	  border-collapse:collapse;
                                	  }

                                	#warn_mail td, #warn_mail th
                                	  {
                                	  font-size:1em;
                                	  border:1px solid #98bf21;
                                	  padding:3px 7px 2px 7px;
                                	  }

                                	#warn_mail tr
                                	  {
                                	  font-size:1.1em;
                                	  text-align:left;
                                	  padding-top:5px;
                                	  padding-bottom:4px;
                                	  background-color:#A7C942;
                                	  color:#ffffff;
                                	  }

                                	#warn_mail tr.alt
                                	  {
                                	  color:#000000;
                                	  background-color:#EAF2D3;
                                	  }
                                	</style>
                                	</head><body>'''
                '''<p style="color:#A52A2A;font-weight:bold;">海象计算任务执行失败,请火速排查!</p>'''
                '''<table id="warn_mail">'''
                '''<tr><th>任务id</th><td>%(f_task_id)d</td></tr>'''
                '''<tr class="alt"><th>任务类型</th><td>%(f_task_type)s</td></tr>'''
                '''<tr><th>失败状态</th><td>%(f_status)s</td></tr>'''
                '''<tr class="alt"><th>失败详情</th><td>%(f_status_desc)s</td></tr>'''
                '''</table></body></html>'''
                % {"f_task_id": f_task_id,
                   "f_task_type": f_task_type,
                   "f_status": f_status,
                   "f_status_desc": f_status_desc})
        MailSender.send_mail(to, subject, body, htmlFlag=True, cc=cc)
Ejemplo n.º 22
0
import web_search
import MailSender

proba = MailSender.MailSender()

proba.sendmail('pajton', 'cao ja sam pajtonnn', '*****@*****.**')
Ejemplo n.º 23
0
def monitoringSendMail( rulesResult ):  

  mailSender=MailSender()
  mailSender.setReportMail(config.reportMail)
  mailSender.setMailFrom(config.mailFrom)
  mailSender.setMailServer(config.mailServer)
  mailSender.setMailPort(config.mailPort)
  mailSender.setMailUser(config.mailUser)
  mailSender.setMailPassword(config.mailPassword)
  mailSender.send('Monitoring report', startTime+"\n"+rulesResult+"\n"+log.getAll())

  return
Ejemplo n.º 24
0
 def setUp(self):
     self.ms = MailSender.MailSender()
Ejemplo n.º 25
0
            size = sizeraw.replace(",", ".")

    # Writes the name and price to the .csv file
    f.write(product + "," + price + "," + size + "\n")
    num = +1

#Compares yesterdays prices with todays
today_dict = dict()
f.close()
with open('ScrapedProducts' + time + '.csv', "r") as today:
    today_reader = csv.reader(today, delimiter=',')
    for row in today_reader:
        today_dict[row[0]] = row[1]

yesterdaytime_str = str(int(str(datetime.now().strftime('%Y%m%d'))) - 1)
with open('ScrapedProducts' + yesterdaytime_str + '.csv',
          "r") as yesterday_file:
    yesterday_reader = csv.reader(yesterday_file, delimiter=',')
    for row in yesterday_reader:
        if row[0] in today_dict:
            if row[1] != today_dict.get(row[0]):
                attach_name = 'NewPrices' + time + '.csv'
                attach = open('NewPrices' + time + '.csv', 'w')
                headers = 'Product, New Price (SEK), Old Price (SEK), Size (inches)\n'
                attach.write(headers)
                attach.write(row[0] + "," + row[1] + "," +
                             today_dict.get(row[0]) + "," + row[2] + "\n")

newmail = MailSender.Mailer(attach_name)
f.close()
Ejemplo n.º 26
0
def try_run():
    MailSender.send("*****@*****.**", "hehe", content, [])
Ejemplo n.º 27
0
def send_ad(qqnums):
    for qq in qqnums:
        mail = qq
	if '@' not in mail:
	    mail = mail + "@qq.com"
        MailSender.send(mail, "hehe", content, [])