VNPY利用郵件引擎,把引數最佳化結果作為附件傳送給預定郵箱
一個簡單的引用,分成兩步,第一步增強郵件引擎,使得可以傳送附件郵件,第二部在回測widget的裡面加入一個新方法,在最佳化完成適合被呼叫。
下面程式碼是加入EmailEngine,新增一個add_attch, 增強send_email,不是很優雅,不過不會對已有用到send_email的不會又太大影響。
def add_attch(self,msg,attch_dir,filename): """ 給郵件資訊物件新增附件 """ file_path = os.path.join(attch_dir, filename) ctype, encoding = mimetypes.guess_type(file_path) if ctype is None: ctype = "application/octet-stream" maintype, subtype = ctype.split("/") with open(file_path, "rb") as r: msg.add_attachment( r.read(), maintype=maintype, subtype=subtype, filename=filename) return msg def send_email(self, subject: str, content: str, receiver: str = "",attch_dir = "",filename = "") -> None: """""" # Start email engine when sending first email. if not self.active: self.start() # Use default receiver if not specified. if not receiver: receiver = SETTINGS["email.receiver"] msg = EmailMessage() msg["From"] = SETTINGS["email.sender"] msg["To"] = receiver msg["Subject"] = subject msg.set_content(content) if attch_dir: msg = self.add_attch(msg,attch_dir,filename) self.queue.put(msg)
然後在BacktesterManager這個類裡面新增一個方法,最佳化結果csv儲存到一個預定folder,併傳送
def save_and_send_csv(self) -> None: """ Save table data into a csv file """ filepath = r"C:\Desktop" filename = self.symbol_line.currentText() + self.start_date_edit.dateTime().toPyDateTime() + ".csv" path = os.path.join(filepath, filename) with open(path, "w", encoding='utf-8-sig') as f: writer = csv.writer(f, lineterminator="\n") writer.writerow(["引數", self.target_display]) for tp in self.backtester_engine.get_result_values(): setting, target_value, _ = tp row_data = [str(setting), str(target_value)] writer.writerow(row_data) self.main_engine.send_email_attchment(subject = filename , content = filename , attch_dir = filepath, filename = filename )
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22259926/viewspace-2927868/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- golang傳送郵件(qq郵箱)Golang
- Java郵件傳送帶附件Java
- Bugfree郵件傳送設定(以QQ郵箱為例)
- 註冊時,給使用者郵箱傳送啟用連結(java 傳送郵件)Java
- 谷歌郵箱,配置傳送郵件密碼谷歌密碼
- Mac郵件怎麼傳送超大附件Mac
- spring boot配置QQ郵箱傳送郵件Spring Boot
- 如何傳送電子郵件到別人郵箱?電子郵件傳送的方法
- laravel 傳送郵件以及引數配置Laravel
- 企業郵箱超大附件怎麼傳送?給你一個妙招
- 定時傳送郵件
- Python 傳送帶有附件的郵件Python
- c# 傳送郵件程式碼,帶附件C#
- linux shell傳送帶附件的郵件Linux
- JavaMail:java使用QQ郵箱傳送郵件簡單版。JavaAI
- node 定時傳送郵件
- kettle 郵件傳送設定
- 利用UTL_SMTP傳送郵件
- 郵箱傳送模組
- 【主機】sendEmail傳送帶有附件的郵件AI
- qq郵箱怎麼發檔案給別的郵箱 qq郵箱如何將文件傳送給別人
- 郵件傳送
- 傳送郵件
- 利用Jmail傳送帶附件的郵件時亂碼的解決方案AI
- Java實現網易企業163郵箱傳送郵件Java
- 配置linux使用mail傳送郵件到163郵箱LinuxAI
- Jenkins 配置郵箱伺服器傳送構建結果Jenkins伺服器
- qq郵箱怎麼傳送資料夾給別人 郵件怎麼把整個資料夾發出去
- 利用Oracle資料庫傳送郵件Oracle資料庫
- 【python】用SMTP模組傳送帶附件的郵件Python
- asp.net定時傳送郵件總結ASP.NET
- SpringBoot整合Mail傳送郵件&傳送模板郵件Spring BootAI
- Laravel 傳送郵件Laravel
- PHP傳送郵件PHP
- Django——郵件傳送Django
- java郵件傳送Java
- Laravel傳送郵件Laravel
- gmail傳送郵件AI