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
- spring boot配置QQ郵箱傳送郵件Spring Boot
- 谷歌郵箱,配置傳送郵件密碼谷歌密碼
- Python 傳送帶有附件的郵件Python
- 如何傳送電子郵件到別人郵箱?電子郵件傳送的方法
- laravel 傳送郵件以及引數配置Laravel
- 定時傳送郵件
- 企業郵箱超大附件怎麼傳送?給你一個妙招
- node 定時傳送郵件
- JavaMail:java使用QQ郵箱傳送郵件簡單版。JavaAI
- SpringBoot整合Mail傳送郵件&傳送模板郵件Spring BootAI
- 傳送郵件
- 郵件傳送
- qq郵箱怎麼發檔案給別的郵箱 qq郵箱如何將文件傳送給別人
- Java實現網易企業163郵箱傳送郵件Java
- 利用Oracle資料庫傳送郵件Oracle資料庫
- Jenkins 配置郵箱伺服器傳送構建結果Jenkins伺服器
- qq郵箱怎麼傳送資料夾給別人 郵件怎麼把整個資料夾發出去
- 【python】用SMTP模組傳送帶附件的郵件Python
- 郵箱傳送模組
- Gitlab伺服器郵箱配置,實現自動為使用者傳送郵件(註冊傳送驗證連結)Gitlab伺服器
- SpringBoot傳送郵件Spring Boot
- phpcms傳送郵件PHP
- 郵件的傳送
- Laravel傳送郵件Laravel
- Laravel 傳送郵件Laravel
- thinkjs 傳送郵件JS
- PHP傳送郵件PHP
- nodejs 傳送郵件NodeJS
- java郵件傳送Java
- python傳送郵件Python
- Django——郵件傳送Django
- gmail傳送郵件AI
- SpringBoot郵件傳送Spring Boot
- python 壓縮檔案並進行郵件傳送(附件格式為zip)Python
- Exchange限制郵箱使用者每天/每分鐘的傳送郵件數量和速率
- win10使用自帶郵箱傳送郵件時直接進傳送箱裡無法完成傳送怎麼解決Win10
- 郵件營銷自動化:批次郵箱API傳送技巧與策略API