B
     9-e                 @   s0   d dl Z d dlmZ d dlZG dd deZdS )    N)ConnectionErrorc               @   s0   e Zd ZdZdZdZdZdddZdd	d
ZdS )IbpyEmailClientzibridgepy-portal.herokuapp.comz127.0.0.1:8000zhttps://zhttp://NFc             C   sP   t |tst|| _|| _|r6d| j| j| jf | _nd| j| j	| jf | _d S )Nz%s%s/handleEmail/api?apiKey=%s)

isinstancestrAssertionErrorapiKey_logTEST_PROTOCOLTEST_DOMAINurlRootPROTOCOLDOMAIN)selfr   logisTest r   G:\My Drive\STUDY\EPAT\09 TBP - Trading & Back-testing Platforms\TBP04 - Backtesting & Live Trading\IB IBridgePy API\02 Python 3.7 IBridgePy_Win_Anaconda37_64\BasicPyLib\sendEmail.py__init__   s    zIbpyEmailClient.__init__c       	   
   C   s   |r| j d|||f  }n| j d||f  }d}d }xV|dk r|d7 }ytj|d}|S  tk
r } z|}td W d d }~X Y q6X q6W | jr| jtd||f   d	S )
Nz&&toEmail=%s&emailTitle=%s&emailBody=%sz&emailTitle=%s&emailBody=%sr         )url   z::send_email: URL=%s and err=%sz)Failed to send email. Something is wrong.)	r   requestsgetr   timesleepr   error__name__)	r   Z
emailTitleZ	emailBodyZtoEmailURLcounterrresponseer   r   r   
send_email   s     
 zIbpyEmailClient.send_email)NF)N)	r   
__module____qualname__r   r
   r   r	   r   r#   r   r   r   r   r      s   
	r   )r   Zrequests.exceptionsr   r   objectr   r   r   r   r   <module>   s   