def test_get_everything_from_news_api(): secret = secrets_manager.get_secret("../secrets/news_api_secrets.json") news_api = NewsApi(api_key=secret.get("api_key")) keyword = 'TESLA' response = news_api.get_everything(keyword=keyword) assert response.get("status") == "ok" assert response.get("totalResults") >= 0
def test_get_top_headlines_from_news_api(): secret = secrets_manager.get_secret("../secrets/news_api_secrets.json") news_api = NewsApi(api_key=secret.get("api_key")) keyword = 'TESLA' articles = news_api.get_top_headlines(keyword=keyword, num_of_articles=3) assert len(articles) == 3 keyword = 'Articlesthatdoesnotexist1234' articles = news_api.get_top_headlines(keyword=keyword, num_of_articles=3) assert len(articles) == 0
def test_alpha_vantage_get_daily_adjusted_quote(): """ Test fetching daily adjusted stock quote from alpha vantage """ path = "../secrets/alpha_vantage_secrets.json" secret = secrets_manager.get_secret(path) api_key = secret.get("api_key") alpha_vantage_data = AlphaVantage(api_key) data = alpha_vantage_data.get_daily_adjusted_quote('TSLA', 'pandas') assert isinstance(data, DataFrame) is True
def test_alpha_vantage_get_quote(): """ Test fetching stock quotes from alpha vantage """ path = "../secrets/alpha_vantage_secrets.json" secret = secrets_manager.get_secret(path) api_key = secret.get("api_key") alpha_vantage_data = AlphaVantage(api_key) data = alpha_vantage_data.get_quote('TSLA') print(data) assert isinstance(data, dict) is True
def test_alpha_vantage_get_percentage_difference_of_quotes(): """ Test calculating the difference of price """ path = "../secrets/alpha_vantage_secrets.json" secret = secrets_manager.get_secret(path) api_key = secret.get("api_key") alpha_vantage_data = AlphaVantage(api_key) data = read_csv('TEST_DAILY_ADJUSTED_QUOTE.csv') percentage_difference, up_down = alpha_vantage_data.get_percentage_difference_of_quotes( data) assert percentage_difference == 1 assert up_down == "🔺"
def test_read_alpha_vantage_api_key(): path = '../secrets/alpha_vantage_secrets.json' secret = secrets_manager.get_secret(path) assert secret.get("api_key") is not None
def test_read_news_api_api_key(): path = '../secrets/news_api_secrets.json' secret = secrets_manager.get_secret(path) assert secret.get("api_key") is not None
import os from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from secrets_manager import get_secret app = Flask(__name__) db_config = get_secret() app.config['SQLALCHEMY_DATABASE_URI'] = ( f'postgresql+psycopg2://{db_config["username"]}:' + f'{db_config["password"]}@' + f'{db_config["host"]}/' + f'{db_config["db_name"]}') app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) migrate = Migrate(app, db) class Transaction(db.Model): __tablename__ = 'transactions' id = db.Column(db.Integer, primary_key=True) first_name = db.Column(db.String()) last_name = db.Column(db.String()) amount = db.Column(db.Float) def __init__(self, first_name: str, last_name: str, amount: float): self.first_name = first_name
from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker import secrets_manager import os # Constants DB_OVERRIDE = os.environ.get("DB_OVERRIDE") ORIGIN = os.environ.get("ORIGIN") RDS_SECRET_ARN = os.environ.get("RDS_SECRET_ARN") AWS_REGION = os.environ.get("AWS_REGION") MYSQL_CONNECTOR = 'mysql+mysqlconnector' if not DB_OVERRIDE: secrets = secrets_manager.get_secret() host = secrets["host"] user = secrets["username"] password = secrets["password"] database = secrets["dbname"] port = str(secrets["port"]) log = False else: host = 'localhost' # host = "docker.for.mac.localhost" user = '******' password = '******' database = 'stock' port = '3306' log = True