Daily Prices

 Main.py


from google.cloud import datastore

import yfinance as yf

import shortuuid

from datetime import datetime


GOOGLE_CLOUD_CLIENT_ID = "sentiment-analysis-379200"

GOOGLE_CLOUD_DAILYPRICES_KEY = "Dailyprices"


# Authenticate to datastore, documented here: https://cloud.google.com/datastore/docs/activate

client = datastore.Client(GOOGLE_CLOUD_CLIENT_ID)


# Use a uuid for unique id for database

company_info_query = client.query(kind="Company_Info")

company_info_results = list(company_info_query.fetch()) 

company_info_tickers = [result['Yahoo_Ticker'].split(" ")[0] for result in company_info_results]


print(company_info_tickers)


def update_datastore(symbol):

    key = client.key(GOOGLE_CLOUD_DAILYPRICES_KEY, str(shortuuid.ShortUUID().random(length=7)))


    stock = yf.Ticker(symbol)

    # round price to two decimals

    latest_price = round(stock.history(period='1d')['Close'].iloc[0], 2)


    task = datastore.Entity(key)

    task.update({

        'Date': datetime.now(),

        'price': latest_price,

        'ticker': symbol,

        'volume': int(stock.info["volume"])

    })

    client.put(task)


for company_info_ticker in company_info_tickers:

    update_datastore(company_info_ticker)


# Crontab:

# 00 23 * * 1-5 /home/sri_mutalik/daily_prices/venv/bin/python3 /home/sri_mutalik/daily_prices/main.py


Requirements.txt


beautifulsoup4==4.12.3

cachetools==5.4.0

certifi==2024.7.4

charset-normalizer==3.3.2

frozendict==2.4.4

google-api-core==2.19.1

google-auth==2.32.0

google-cloud-core==2.4.1

google-cloud-datastore==2.19.0

googleapis-common-protos==1.63.2

grpcio==1.64.1

grpcio-status==1.64.1

html5lib==1.1

idna==3.7

lxml==5.2.2

multitasking==0.0.11

numpy==1.24.4

pandas==2.0.3

peewee==3.17.6

platformdirs==4.2.2

proto-plus==1.24.0

protobuf==4.25.3

pyasn1==0.6.0

pyasn1-modules==0.4.0

python-dateutil==2.9.0.post0

pytz==2024.1

requests==2.32.3

rsa==4.9

shortuuid==1.0.13

six==1.16.0

soupsieve==2.5

tzdata==2024.1

urllib3==2.2.2

webencodings==0.5.1

yfinance==0.2.40


No comments:

Post a Comment

Notes 3-18-25

https://uconn-sa.blogspot.com/  We were able to launch an app engine program from our compute engine instance.   I'd like to get all wo...