Exemplo n.º 1
0
def send_email():
    sender_env = AWSClients().sender()
    recipient_env = AWSClients().recipient()
    logs = 'https://us-west-2.console.aws.amazon.com/cloudwatch/home#logStream:group=/aws/lambda/robinhood'
    git = 'https://github.com/thevickypedia/stock_hawk'
    footer_text = "\n----------------------------------------------------------------" \
                  "----------------------------------------\n" \
                  "A report on the list shares you have purchased.\n" \
                  "The data is being collected using http://api.robinhood.com/," \
                  f"\nFor more information check README.md in {git}"
    sender = f'Robinhood Monitor <{sender_env}>'
    recipient = [f'{recipient_env}']
    title = f'Investment Summary as of {dt_string}'
    text = f'{overall_result}\n\n{port_head}\n{profit}\n{loss}\n\n{graph_msg}\n\n' \
           f'Navigate to check logs: {logs}\n\n{footer_text}'
    attachment = 'placeholder'
    # # use this if you wish to have conditional emails/notifications
    # text = f'{watcher()}\n\nNavigate to check logs: {logs}\n\n{footer_text}'
    email = Emailer(sender, recipient, title, text, attachment)
    # directory = os.listdir("tmp")
    # graph_status = []
    # for item in directory:
    #     if item:
    #         os.remove(os.path.join("tmp", item))
    #         graph_status.append(item.strip('.png'))
    # if graph_status:
    #     print(f"\nRemoved graph generated for {graph_status}")
    # else:
    #     print('No files to remove')
    return email
Exemplo n.º 2
0
def send_whatsapp(data, context):
    if market_status():
        whatsapp_msg = send_email()
        if whatsapp_msg:
            from twilio.rest import Client
            whatsapp_send = AWSClients().send()
            whatsapp_receive = AWSClients().receive()
            sid = AWSClients().sid()
            token = AWSClients().token()
            from_number = f"whatsapp:{whatsapp_send}"
            to_number = f"whatsapp:{whatsapp_receive}"
            client = Client(sid, token)
            client.messages.create(
                body=
                f'{dt_string}\n\nWatchlist Notification\n\n{whatsapp_msg}Log info here\n{logs}',
                from_=from_number,
                to=to_number)
Exemplo n.º 3
0
def send_email():
    email_data = email_formatter()
    if email_data:
        from lib.emailer import Emailer
        sender_env = AWSClients().sender()
        recipient_env = AWSClients().recipient()
        git = 'https://github.com/thevickypedia/black_pearl'
        footer_text = "\n----------------------------------------------------------------" \
                      "----------------------------------------\n" \
                      "A report on the list shares on your watchlist that has either deceeded the MIN threshold or " \
                      "exceeded the MAX limit value.\n" \
                      "The data is being collected from https://finance.yahoo.com," \
                      f"\nFor more information check README.md in {git}"
        sender = f'Black Pearl <{sender_env}>'
        recipient = [f'{recipient_env}']
        title = f'Black Pearl Alert as of {dt_string}'
        text = f'Watchlist Notification\n\n{email_data}Navigate to check logs: {logs}\n\n{footer_text}'
        Emailer(sender, recipient, title, text)
        return email_data
Exemplo n.º 4
0
def send_whatsapp(data, context):
    if send_email():
        whatsapp_send = AWSClients().send()
        whatsapp_receive = AWSClients().receive()
        sid = AWSClients().sid()
        token = AWSClients().token()
        client = Client(sid, token)
        from_number = f"whatsapp:{whatsapp_send}"
        to_number = f"whatsapp:{whatsapp_receive}"
        client.messages.create(
            body=
            f'{dt_string}\nRobinhood Report\n{overall_result}\n\nCheck your email for '
            f'summary',
            from_=from_number,
            to=to_number)
        print(
            f"Script execution time: {round(float(time.time() - start_time), 2)} seconds"
        )
    else:
        return None
Exemplo n.º 5
0
#! /usr/bin/env python3
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

import boto3

from lib.aws_client import AWSClients

acc_key = AWSClients().access_key()
secret_key = AWSClients().secret_key()


class Emailer:
    def __init__(self, sender: str, recipients: list, title: str, text: str):
        boto3_ses_client = boto3.Session(
            # vig
            aws_access_key_id=acc_key,
            aws_secret_access_key=secret_key).client('ses',
                                                     region_name='us-west-2')

        response_ = self.send_mail(boto3_ses_client, sender, recipients, title,
                                   text)
        print(response_)

    def create_multipart_message(self, sender: str, recipients: list,
                                 title: str, text: str) -> MIMEMultipart:
        multipart_content_subtype = 'alternative' if text else 'mixed'
        msg = MIMEMultipart(multipart_content_subtype)
        msg['Subject'] = title
        msg['From'] = sender
        msg['To'] = ', '.join(recipients)
Exemplo n.º 6
0
from datetime import datetime, timedelta

import requests
import os
from pyrh import Robinhood
from twilio.rest import Client

from lib.aws_client import AWSClients
from lib.emailer import Emailer

start_time = time.time()
now = datetime.now() - timedelta(hours=5)
dt_string = now.strftime("%A, %B %d, %Y %I:%M %p")
print(f'\n{dt_string}')

u = AWSClients().user()
p = AWSClients().pass_()
q = AWSClients().qr_code()

rh = Robinhood()
rh.login(username=u, password=p, qr_code=q)

print('Gathering your investment details...')


def account_user_id():
    ac = rh.get_account()
    user = ac['account_number']
    return user