예제 #1
0
def invoice_send_email(entity, receiver, attachment):
    # Send email
    scrapymail = Email()

    if (attachment is None) or attachment.empty:
        subject = '[PAM Tax Checking] - {0} 发票无异常 {1}'.format(
            TIME['TODAY'], entity)
        content = 'Hi All,\r\n\r\n{}的发票无异常记录。\r\n\r\nThanks.'.format(entity)
        scrapymail.send(subject=subject,
                        content=content,
                        receivers=receiver,
                        attachment=None)
    else:
        subject = '[PAM Tax Checking] - {0} 发票异常清单 {1}'.format(
            TIME['TODAY'], entity)
        content = 'Hi All,\r\n\r\n请查看附件关于{}的发票异常记录。\r\n\r\nThanks.'.format(
            entity)
        entity_path = df_to_excel(df=attachment,
                                  path=PATH['FILE_DIR'],
                                  file_name=PATH['ATTACHMENT_FILE'].format(
                                      TIME['TODAY'], entity),
                                  sheet_name=entity)
        scrapymail.send(subject=subject,
                        content=content,
                        receivers=receiver,
                        attachment=entity_path)
        logger.info('Delete attachment file.')
        os.remove(entity_path)

    scrapymail.close()
예제 #2
0
        datas = ExcelReader(self.excel).data
        for d in datas:
            with self.subTest(data=d):
                self.sub_setUp()
                self.driver.find_element(*self.locator_kw).send_keys(
                    d['search'])
                self.driver.find_element(*self.locator_su).click()
                time.sleep(2)
                links = self.driver.find_elements(*self.locator_result)
                for link in links:
                    logger.info(link.text)
                self.sub_tearDown()


if __name__ == '__main__':
    report = REPORT_PATH + '\\report.html'
    with open(report, 'wb') as f:
        runner = HTMLTestRunner(f,
                                verbosity=2,
                                title='从0搭建测试框架 灰蓝',
                                description='修改html报告')
        runner.run(TestBaiDu('test_search'))
    e = Email(title='百度搜素测试报告',
              message='这是今天的测试报告,请查收!',
              receiver='*****@*****.**',
              server='...',
              sender='...',
              password='******',
              path=report)
    e.send()
예제 #3
0
        data['nodes'][d] = [x for x in cnodes if int(x['days_to_expire']) <= d]
        cnodes = [x for x in cnodes if int(x['days_to_expire']) > d]

    log.debug("=== data ===")
    log.debug(data)
    log.debug("=== template ===")
    log.debug(tpl.render(data))
    log.debug("===  end  ===")

    if CFG['email_users']:
        to = c
        if '@' not in c:
            to += '@you.com'

        email = Email('[TSM] Expiration warning for contact %s' % c,
                      tpl, [to],
                      bcc=CFG['bcc_address'],
                      replyto=CFG['support_address'])
        email.send()

        log.info("email sent to %s" % to)

# Now send a summary email to the admins
expire = [x for x in alert.events if x['retire'] == 0 and x['days_to_expire']]
data = {
    'retire': retire,
    'expire': [x for x in expire if int(x['days_to_expire']) < 1],
    'expire_soon': [x for x in expire if int(x['days_to_expire']) >= 1],
}

tpl = Template('%s_escalation' % alert.search_name)
예제 #4
0
    condition_done = '[Timestamp] >= {0} AND [Source] = {1}'\
        .format(get_sql_list(TIME['TODAY']), get_sql_list(PATH['SITE']))
    entities_run = exist_db.get_to_runs(table_name=DB['LOG_TABLE_NAME'],
                                        condition=condition_done,
                                        source=PATH['SITE'])

for entity in entities_run:
    entity_object = Haozu(entity)
    entity_object.run()

    with ODBC(config=keys.dbconfig_mkt) as entity_db:
        entity_db.upload(df=entity_object.df['df'],
                         table_name=DB['DETAIL_TABLE'],
                         new_id=PATH['SITE'])
        entity_db.upload(df=entity_object.df['info'],
                         table_name=DB['INFO_TABLE'],
                         new_id=PATH['SITE'],
                         dedupe_col='Source_ID')
        entity_db.log(Entity=entity,
                      Timestamp=TIME['TODAY'],
                      Source=PATH['SITE'],
                      start=1,
                      end=len(entity_object.df['info']))

scrapyemail = Email()
scrapyemail.send(subject='[Scrapy] ' + DB['DETAIL_TABLE'],
                 content='Done',
                 attachment=PATH['LOG_PATH'])
scrapyemail.close()
exit(0)
예제 #5
0
if feed_rss:
    fcntl.flock(feed_rss, fcntl.LOCK_UN)
    feed_rss.close()

if alert.getSeverityTag() in ['CRITICAL', 'HIGH']:
    # Push through Pushbullet
    API_KEY = ''

    sys.path.insert(0, '/usr/lib/python2.6/site-packages')
    import pushybullet as pb
    api = pb.PushBullet(API_KEY)

    title = '%s: %s' % (alert.getSeverityTag(), alert.numEventsStr())

    link = pb.LinkPush('https://druid', title)

    # Send it off!
    for c in api.contacts():
        c.push(link)

if CFG['email_admins']:
    if alert.search_name.startswith('Generic Alert'):
        subject = '[%s] %s' % (alert.getSeverityTag(), alert.numEventsStr())
    else:
        subject = '[%s] %s' % (alert.getSeverityTag(), alert.search_name)

    email = Email('[DRUID] %s' % subject, tpl, CFG['admin_address'])
    email.send()

    log.info("email sent - %s" % subject)
예제 #6
0
        'filespaces': cfiles,
    }

    log.debug("=== data ===")
    log.debug(pprint.pformat(data))
    log.debug("=== template ===")
    log.debug(tpl.render(data))
    log.debug("===  end  ===")

    if CFG['email_users']:
        to = c
        if '@' not in c:
            to += '@you.com'

        email = Email('[TSM] Failed backups for contact %s' % c,
                      tpl, [to],
                      bcc=CFG['bcc_address'],
                      replyto=CFG['support_address'])
        email.send()

        log.info("email sent to %s" % to)

# Now send a summary email to the admins, but only for stuff older than ESCALATION_DATE

data = {
    'escalation_date': ESCALATION_DATE,
    'nodes': filterByAge(nodes, ESCALATION_DATE),
    'filespaces': filterByAge(filespaces, ESCALATION_DATE),
}

tpl = Template('%s_escalation' % alert.search_name)
예제 #7
0
for c, ev in events:
    if not c:
        # Ignore events we don't have a contact for
        continue
    log.debug("Contact: %s", c)

    data = {
        'contact': c,
        'data': [x for x in ev],
    }

    log.debug("=== data ===")
    log.debug(pprint.pformat(data))
    log.debug("=== template ===")
    log.debug(tpl.render(data))
    log.debug("===  end  ===")

    if CFG['email_users']:
        to = c
        if '@' not in c:
            to += '@you.com'

        email = Email('[TSM] Unauthorized access for contact %s' % c,
                      tpl, [to],
                      bcc=CFG['bcc_address'],
                      replyto=CFG['support_address'])
        email.send()

        log.info("email sent to %s" % to)
예제 #8
0
    # Upload to database
    entity_db = ODBC(keys.dbconfig)
    entity_db.upload(df=tax_df, table_name=DB['TAX_INFO_TABLE'])
    entity_db.upload(df=tax_detail_df, table_name=DB['TAX_DETAIL_TABLE'])
    entity_db.log(start=TIME['PRE3MONTH'], end=TIME['TODAY'], Timestamp=TIME['TIMESTAMP'], Source=PATH['SITE'],
                  Entity=row['Entity_Name'])
    entity_db.close()

# Ensure failure of scraping process do not interrupt email and sp execution
with ODBC(keys.dbconfig) as execute_db:
    # Update Irregular_Ind by executing stored procedure
    execute_db.call_sp(sp='CHN.Irregular_Tax_Refresh', table_name=DB['TAX_DETAIL_TABLE'],
                       table_name2=DB['TAX_DETAIL_TABLE'])
    for index, row in access.iterrows():
        # Get irregular record
        att = execute_db.call_sp(sp='CHN.Irregular_Tax_ETL', output=True, table_name=DB['TAX_DETAIL_TABLE'],
                                 entity_name=row['Entity_Name'])
        numeric_col = ['金额', '单价', '税率', '税额']

        if att is not None:
            att[numeric_col] = att[numeric_col].apply(pd.to_numeric)

        invoice_send_email(entity=row['Entity_Name'], receiver=row['Email_List'], attachment=att)

# Send email summary
scrapyemail_summary = Email()
scrapyemail_summary.send('[Scrapy]' + PATH['SITE'], 'Done', PATH['LOG_PATH'],
                         receivers='[email protected];[email protected]')
scrapyemail_summary.close()
exit(0)