コード例 #1
0
ファイル: tencent.py プロジェクト: tufei8438/stockquant
 def run(self):
     while self._running:
         try:
             self._run()
             time.sleep(self._interval)
         except Exception:
             logger.exception("运行TencentRunner异常")
コード例 #2
0
ファイル: tencent.py プロジェクト: tufei8438/stockquant
 def run(self):
     while self._running:
         try:
             self._run()
             time.sleep(self._interval)
         except Exception:
             logger.exception("运行TencentRunner异常")
コード例 #3
0
ファイル: holiday.py プロジェクト: tufei8438/stockquant
    def get_holidays_by_api(cls):
        today = datetime.datetime.now()
        params = {'d': today.year}
        headers = {'apikey': cls._holiday_api_key}

        try:
            r = requests.get(cls._holiday_api_url, params=params, headers=headers)
            if r.status_code == 200:
                holidays = r.json()
                return holidays.get(str(today.year))
            else:
                return []
        except Exception:
            logger.exception("获取节假日接口异常")
            return []
コード例 #4
0
ファイル: mail.py プロジェクト: tufei8438/stockquant
    def send(self, subject, content, subtype='plain', from_=None, to_=None):
        msg = MIMEText(content, _subtype=subtype, _charset='utf-8')
        msg["Subject"] = subject
        msg["From"] = from_ or self._user
        msg["To"] = to_ or self._to

        try:
            smtp = smtplib.SMTP_SSL(self._smtp, timeout=30)
            smtp.login(self._user, self._pwd)
            smtp.sendmail(self._user, self._to, msg.as_string())
            smtp.close()
            return True
        except smtplib.SMTPException:
            logger.exception("邮件发送失败。主题:[%s] 内容:[%s]" % (subject, content))
            return False
コード例 #5
0
    def get_holidays_by_api(cls):
        today = datetime.datetime.now()
        params = {'d': today.year}
        headers = {'apikey': cls._holiday_api_key}

        try:
            r = requests.get(cls._holiday_api_url,
                             params=params,
                             headers=headers)
            if r.status_code == 200:
                holidays = r.json()
                return holidays.get(str(today.year))
            else:
                return []
        except Exception:
            logger.exception("获取节假日接口异常")
            return []