コード例 #1
0
 def __init__(self, from_address, to_address, subject_prefix):
     self.factory = Sendmail(from_address)
     self.from_address = from_address
     self.to_address = to_address
     self.subject_prefix = subject_prefix
     self.alert_cache = collections.defaultdict(list)
     self.looping_call = LoopingCall(self.send_cached_alerts)
コード例 #2
0
 def run_report(self, full_report=False, test_mail=False):
     mail = Sendmail(self._config['mail'], template_report=True)
     self.get_projects()
     report = []
     for project_identifier, project in self.projects.items():
         project_report = {
             'id': project['id'],
             'identifier': project['identifier'],
             'name': project['name'],
             'sla': project['sla'],
             'issues': []
         }
         for issue in rm.get_issues(project['id']):
             time_window = rm.in_time_window(project, issue)
             if time_window:
                 if time_window['percent'] == 100 or full_report:
                     issue['project_sla'] = project['sla']
                     issue['time_window'] = time_window['name']
                     issue['time_after_creation'] = time_diff(
                         issue['created_on'], False)
                     issue['created_on_local'] = str(
                         date_from_redmine(issue['created_on'], True))
                     issue['important'] = time_window[
                         'important'] if 'important' in time_window else False
                     project_report['issues'].append(issue)
         if project_report['issues']:
             report.append(project_report)
     rcpt = self._config['main']['report_email']
     if test_mail:
         rcpt = self._config['main']['test_email']
     if report:
         logging.info("Send report to %s" % rcpt)
         mail.send_report(rcpt, report)
     else:
         logging.info("Nothing to report")
コード例 #3
0
ファイル: alerts.py プロジェクト: primehat23/sputnik
 def __init__(self, from_address, to_address, subject_prefix):
     self.factory = Sendmail(from_address)
     self.from_address = from_address
     self.to_address = to_address
     self.subject_prefix = subject_prefix
     self.alert_cache = collections.defaultdict(list)
     self.looping_call = LoopingCall(self.send_cached_alerts)
コード例 #4
0
 def run_notify(self, reset_history=False, test_mail=False):
     mail = Sendmail(self._config['mail'])
     if reset_history:
         logging.info("Reset history")
         self.hdb.reset()
     self.get_projects()
     for project_identifier, project in self.projects.items():
         for issue in rm.get_issues(project['id']):
             time_window = rm.in_time_window(project, issue)
             if time_window:
                 if self.hdb.not_sent(issue['id'], time_window['name']):
                     if time_window['rcpt']:
                         issue['rcpt'] = time_window['rcpt']
                         issue['project_identifier'] = project_identifier
                         issue['project_sla'] = project['sla']
                         issue['time_window'] = time_window['name']
                         issue['time_after_creation'] = time_diff(
                             issue['created_on'], False)
                         issue['created_on_local'] = str(
                             date_from_redmine(issue['created_on'], True))
                         issue['notify_roles'] = issue_get_notify_roles(
                             time_window)
                         issue['important'] = time_window[
                             'important'] if 'important' in time_window else False
                         if test_mail:
                             issue['rcpt_origin'] = copy.deepcopy(
                                 issue['rcpt'])
                             issue['rcpt'] = self._config['main'][
                                 'test_email']
                         issue_log_info(issue)
                         if mail.send_issue(issue=issue,
                                            important=issue['important']):
                             self.hdb.sent(issue['id'],
                                           issue['time_window'])
                     else:
                         issue_log_debug(issue, 'No notify roles!')
                 else:
                     issue_log_debug(issue, 'In history!')
コード例 #5
0
ファイル: alerts.py プロジェクト: primehat23/sputnik
class Alerts:
    def __init__(self, from_address, to_address, subject_prefix):
        self.factory = Sendmail(from_address)
        self.from_address = from_address
        self.to_address = to_address
        self.subject_prefix = subject_prefix
        self.alert_cache = collections.defaultdict(list)
        self.looping_call = LoopingCall(self.send_cached_alerts)

    def send_alert(self, message, subject, cache=True):
        if cache:
            self.alert_cache[subject].append(message)
        else:
            log.msg("Sending alert: %s/%s" % (subject, message))
            self.factory.send_mail(message, subject=self.subject_prefix + " " + subject, to_address=self.to_address)

    def send_cached_alerts(self):
        for subject, messages in self.alert_cache.items():
            self.send_alert("\n---\n".join(messages), subject, cache=False)
            del self.alert_cache[subject]

    def start(self, time=60):
        self.looping_call.start(time, now=False)
コード例 #6
0
class Alerts():
    def __init__(self, from_address, to_address, subject_prefix):
        self.factory = Sendmail(from_address)
        self.from_address = from_address
        self.to_address = to_address
        self.subject_prefix = subject_prefix
        self.alert_cache = collections.defaultdict(list)
        self.looping_call = LoopingCall(self.send_cached_alerts)

    def send_alert(self, message, subject, cache=True):
        if cache:
            self.alert_cache[subject].append(message)
        else:
            log.msg("Sending alert: %s/%s" % (subject, message))
            self.factory.send_mail(message, subject=self.subject_prefix + " " + subject,
                                   to_address=self.to_address)

    def send_cached_alerts(self):
        for subject, messages in self.alert_cache.items():
            self.send_alert('\n---\n'.join(messages), subject, cache=False)
            del self.alert_cache[subject]

    def start(self, time=60):
        self.looping_call.start(time, now=False)
コード例 #7
0
ファイル: goo.py プロジェクト: gc313/goo
	sh_count = 0
	DataAPI('http://apis.baidu.com/apistore/stockservice/stock?stockid=sh600663&list=0')
	logging.info('插入数据%s条' % sh_count)
	'''
    try:
        logging.info('程序运行')
        while 1:

            #定时运行,每天凌晨00:00开始采集数据
            run_time = Now()[11:16]
            if run_time == '00:00':
                #if 1:
                logging.info('开始采集数据')
                #加个计数功能,记录每天插入了多少条记录

                sh_count = 0
                sz_count = 0

                Get_sh_data(target, lis)
                Get_sz_data(target, lis)
                Sendmail('数据采集工作已于 %s 完成,沪市A股采集数据%s条,深市A股采集数据%s条。' %
                         (Now(), sh_count, sz_count))
                logging.info('数据采集完成')
            time.sleep(50)
    except Exception as e:
        logging.error('%s' % e)
        Sendmail('%s 程序报错:%s ' % (Now(), e))
    finally:
        Sendmail('程序已结束运行 at %s ' % Now())
        logging.info('程序结束运行')
コード例 #8
0
ファイル: riskmanager.py プロジェクト: treverson/sputnik
                    result = "WARNING"
                else:
                    if user.username in self.low_margin_users:
                        del self.low_margin_users[user.username]  # resolved
                    if user.username in self.bad_margin_users:
                        del self.bad_margin_users[user.username]  # resolved
                    result = "OK"

                log.msg("%s: %s / %d %d %d" %
                        (result, user.username, low_margin, high_margin,
                         self.cash_positions[user.username]))


if __name__ == "__main__":
    log.startLogging(sys.stdout)

    session = database.make_session()

    safe_price_subscriber = connect_subscriber(
        config.get("safe_price_forwarder", "zmq_backend_address"))
    safe_price_subscriber.subscribe('')
    sendmail = Sendmail(config.get("riskmanager", "from_email"))
    accountant = AccountantProxy(
        "dealer", config.get("accountant", "riskmanager_export"),
        config.getint("accountant", "riskmanager_export_base_port"))

    riskmanager = RiskManager(session, sendmail, safe_price_subscriber,
                              accountant)

    reactor.run()
コード例 #9
0
def email_conversation():
    """Let me see what else Sophie needs to learn."""
    Sendmail().sendmail(from_addr="",
                        to_addrs=["*****@*****.**"],
                        msg="\n".join(conversation))
コード例 #10
0
if __name__ == '__main__':
    log.startLogging(sys.stdout)

    accountant = AccountantProxy(
        "dealer", config.get("accountant", "cashier_export"),
        config.getint("accountant", "cashier_export_base_port"))

    session = db.make_session()
    bitcoin_conf = config.get("cashier", "bitcoin_conf")

    log.msg('connecting to bitcoin client')

    bitcoinrpc = {'BTC': BitcoinRpc(bitcoin_conf, 1)}
    compropago = Compropago(config.get("cashier", "compropago_key"))
    cold_wallet_period = config.getint("cashier", "cold_wallet_period")
    sendmail = Sendmail(config.get("administrator", "email"))
    minimum_confirmations = config.getint("cashier", "minimum_confirmations")
    alerts_proxy = AlertsProxy(config.get("alerts", "export"))
    bitgo_config = {
        'use_production': not config.getboolean("cashier", "testnet"),
        'client_id': config.get("bitgo", "client_id"),
        'client_secret': config.get("bitgo", "client_secret")
    }
    bitgo = BitGo(**bitgo_config)
    bitgo_private_key_file = config.get("cashier", "bitgo_private_key_file")

    cashier = Cashier(
        session,
        accountant,
        bitcoinrpc,
        compropago,