コード例 #1
0
def get_results(tickers=None):
    """
    Given a list of stock tickers, this print formatted results to the terminal.
    """
    if tickers == ['']:
        return

    stocks = QuarterlyReport.get_stocks(tickers)

    if verbose:
        string_header = '{:<10}'.format('Ticker') + '{:<17}'.format('Earnings Date')
        string_to_line = ''
        if peg_ratio:
            string_header += '{:<13}'.format('Peg Ratio')
        if pe_ratio:
            string_header += '{:<13}'.format('PE Ratio')
        if rsi:
            string_header += '{:<13}'.format('RSI')
        if fifty_two:
            string_header += '{:<20}'.format('52Wk H&L')
        string_header += '{:<12}'.format('Price')
        print(string_header)
        for stock in stocks:
            string_to_line = '{:<10}'.format(stock.ticker) + '{:<17}'.format(stock.earnings_date)
            if peg_ratio:
                string_to_line += '{:<13}'.format(str(stock.peg_ratio))
            if pe_ratio:
                string_to_line += '{:<13}'.format(str(stock.pe_ratio))
            if rsi:
                string_to_line += '{:<13}'.format(str(stock.rsi))
            if fifty_two:
                string_to_line += '{:<20}'.format(str(stock.fifty_two))
            string_to_line += '{:<12}'.format(str(stock.price))
            print(string_to_line)
    return stocks
コード例 #2
0
def send_email(tickers=None, to_addr='your_email_here@your_domain.com'):
    """
    Given a list of stock tickers, this will send an email report formatted as an HTML table to the designated address.
    """

    stocks = QuarterlyReport.get_stocks(tickers)

    if ('email_sender' and 'email_cred' and 'email_receiver' and 'port'
            and 'smtp') in globals():
        # Create a message summarizing the best deals.
        message = MIMEMultipart('alternative')

        message['Subject'] = 'TakeStock Report'
        message['From'] = email_sender
        html = ''
        if peg_ratio:
            html = """\
            <table border=1>
            <thead><tr><td>Stock Symbol</td><td>Earnings Date</td><td>PEG Ratio</td><td>Price</td></tr></thead>
            <tbody>
            """
        else:
            html = """\
            <table border=1>
            <thead><tr><td>Stock Symbol</td><td>Earnings Date</td><td>Price</td></tr></thead>
            <tbody>
            """

        for stock in stocks:
            if peg_ratio:
                html += "<tr>" + "<td>" + stock.ticker + "</td>" + "<td>" + stock.earnings_date + "</td>" + \
                        "<td>" + str(stock.peg_ratio) + "</td>" + "<td>" + str(stock.price) + "</td></tr>"
            else:
                html += "<tr>" + "<td>" + stock.ticker + "</td>" + "<td>" + stock.earnings_date + "</td>" + "<td>" + \
                        str(stock.price) + "</td></tr>"

        html += '</tbody></table>'

        text = MIMEText(html, 'html')
        message.attach(text)
        # Email the deals.
        message['To'] = email_receiver
        server = smtplib.SMTP(smtp + ":" + port)
        # server.ehlo()
        server.starttls()
        server.login(email_sender, email_cred)
        server.sendmail(email_sender, email_receiver, message.as_string())
        server.quit()
        return html
コード例 #3
0
def send_email(tickers=None, to_addr='your_email_here@your_domain.com'):
    """
    Given a list of stock tickers, this will send an email report formatted as an HTML table to the designated address.
    """

    stocks = QuarterlyReport.get_stocks(tickers)

    if ('email_sender' and 'email_cred' and 'email_receiver' and 'port' and 'smtp') in globals():
        # Create a message summarizing the best deals.
        message = MIMEMultipart('alternative')

        message['Subject'] = 'TakeStock Report'
        message['From'] = email_sender
        html = ''
        if peg_ratio:
            html = """\
            <table border=1>
            <thead><tr><td>Stock Symbol</td><td>Earnings Date</td><td>PEG Ratio</td><td>Price</td></tr></thead>
            <tbody>
            """
        else:
            html = """\
            <table border=1>
            <thead><tr><td>Stock Symbol</td><td>Earnings Date</td><td>Price</td></tr></thead>
            <tbody>
            """

        for stock in stocks:
            if peg_ratio:
                html += "<tr>" + "<td>" + stock.ticker + "</td>" + "<td>" + stock.earnings_date + "</td>" + \
                        "<td>" + str(stock.peg_ratio) + "</td>" + "<td>" + str(stock.price) + "</td></tr>"
            else:
                html += "<tr>" + "<td>" + stock.ticker + "</td>" + "<td>" + stock.earnings_date + "</td>" + "<td>" + \
                        str(stock.price) + "</td></tr>"

        html += '</tbody></table>'

        text = MIMEText(html, 'html')
        message.attach(text)
        # Email the deals.
        message['To'] = email_receiver
        server = smtplib.SMTP(smtp + ":" + port)
        # server.ehlo()
        server.starttls()
        server.login(email_sender, email_cred)
        server.sendmail(email_sender, email_receiver, message.as_string())
        server.quit()
        return html
コード例 #4
0
def get_results(tickers=None):
    """
    Given a list of stock tickers, this print formatted results to the terminal.
    """
    if tickers == ['']:
        return

    stocks = QuarterlyReport.get_stocks(tickers)

    if verbose:
        string_header = '{:<10}'.format('Ticker') + '{:<17}'.format(
            'Earnings Date')
        string_to_line = ''
        if peg_ratio:
            string_header += '{:<13}'.format('Peg Ratio')
        if pe_ratio:
            string_header += '{:<13}'.format('PE Ratio')
        if rsi:
            string_header += '{:<13}'.format('RSI')
        if fifty_two:
            string_header += '{:<20}'.format('52Wk H&L')
        string_header += '{:<12}'.format('Price')
        print(string_header)
        for stock in stocks:
            string_to_line = '{:<10}'.format(stock.ticker) + '{:<17}'.format(
                stock.earnings_date)
            if peg_ratio:
                string_to_line += '{:<13}'.format(str(stock.peg_ratio))
            if pe_ratio:
                string_to_line += '{:<13}'.format(str(stock.pe_ratio))
            if rsi:
                string_to_line += '{:<13}'.format(str(stock.rsi))
            if fifty_two:
                string_to_line += '{:<20}'.format(str(stock.fifty_two))
            string_to_line += '{:<12}'.format(str(stock.price))
            print(string_to_line)
    return stocks
コード例 #5
0
 def test_get_share_price(self):
     share_price = QuarterlyReport.get_share_price(testing_ticker)
     self.assertIsNotNone(share_price)
     self.assertIn('$', share_price)
コード例 #6
0
 def test_get_rsi(self):
     rsi = QuarterlyReport.get_rsi(testing_ticker)
     self.assertIsNotNone(rsi)
     self.assertTrue(is_numeric(float(rsi)))
コード例 #7
0
 def test_get_peg_ratio(self):
     peg = QuarterlyReport.get_peg_ratio(testing_ticker)
     self.assertIsNotNone(peg)
     self.assertTrue(is_numeric(float(peg)))
コード例 #8
0
 def test_get_fifty_two_week_high_low(self):
     hi_low = QuarterlyReport.get_fifty_two_week_high_low(testing_ticker)
     self.assertIsNotNone(hi_low)
     self.assertIn('H', hi_low)
     self.assertIn('L', hi_low)
コード例 #9
0
 def test_get_earnings_date(self):
     self.assertIsNotNone(QuarterlyReport.get_earnings_date(testing_ticker))
コード例 #10
0
 def test_get_share_price(self):
     share_price = QuarterlyReport.get_share_price(testing_ticker)
     self.assertIsNotNone(share_price)
     self.assertIn('$', share_price)
コード例 #11
0
 def test_get_rsi(self):
     rsi = QuarterlyReport.get_rsi(testing_ticker)
     self.assertIsNotNone(rsi)
     self.assertTrue(is_numeric(float(rsi)))
コード例 #12
0
 def test_get_peg_ratio(self):
     peg = QuarterlyReport.get_peg_ratio(testing_ticker)
     self.assertIsNotNone(peg)
     self.assertTrue(is_numeric(float(peg)))
コード例 #13
0
 def test_get_fifty_two_week_high_low(self):
     hi_low = QuarterlyReport.get_fifty_two_week_high_low(testing_ticker)
     self.assertIsNotNone(hi_low)
     self.assertIn('H', hi_low)
     self.assertIn('L', hi_low)
コード例 #14
0
 def test_get_earnings_date(self):
     self.assertIsNotNone(QuarterlyReport.get_earnings_date(testing_ticker))