Stock Checker & emailer v10
Yfinance sucks! april 2025 they changed their script to limit & ban ips that make multiple ticker calls per minute. so i had to change to alpha venture to make the script work.
1) you need to sign up for a free API key. fill in name & email. you can make it up since it generates a # key on the page
https://www.alphavantage.co/support/#api-key
2) add your new api key to your hide.py file
sendEmail = "you@gmail.com"
sendAppPssd = "your_app_password"
recEmail = "someone@gmail.com"
iex_api_key = "YOUR_IEX_API_KEY"
3) open a terminal shell. navigate to where your new v10 script is located. activate your virtual environment & use pip to install iexfinance
cd PathToYourScriptDirectory
source env/bin/activate
pip install iexfinance
note : the new script has to time out 15 seconds each call because of the limitations to the FREE account. if you want it quicker then you’re gonna have to sign up for a paid account. it sends me an email each morning so i don’t see the +1 minute time delay unless you’re really watching it or have lots of stocks you’re checking.
=========================================
UPDATE 04/2024 <————— COOL!!!
>> RUN PYTHON SCRIPTS AUTOMATICALLY DAILY AT CERTAIN TIME <<
Really Cool Update!! on most python & apple script sites i came across tons of people trying to get a script to automatically execute every day at a given time. usually the answers involved downloading special plugins or apps including running in the background continuously (not ideal), signing up for PythonAnywhere & have it run there (also not ideal + $ monthly fee) or crontab (external site so not ideal). Calendar Alarm doesn’t work with scripts. so below is a workaround that works & uses all built-in processes.
UPDATE 03/2024 : added a virtual environment so i can add plugins as needed. i’ll swap out the new apple script example below. No more need to create a Nuitka standalone app, just set path to the python script.
FYI when i made the demo NVDA was $312.64. today it’s $878.36!!
========
Really cool & useful python script I wrote that checks your stock portfolio & sends an email of your daily gain/loss. Sure you can log in to your Trading account & type in your password to get it. This simplifies it by not needing to go into your account to see your daily progress. Just run the script daily & check your email
Need to have a Gmail Account as the sender email.
2023 Google’s new security settings require you to set 2-Step Verification.
Settings/Security/2-Step Verification/App Passwords - Other -> create new 16 character App Password
Edit hide.py with new credentials.
Edit stocks.csv with stock tickers & number of share. Keep the same “AAPL” (capital letters & quotations) format to tickers
stockCheckerEmailer_v6.py, hide.py & stocks.csv need to be in the same directory.
DO NOT RENAME SCRIPTS OR CSV FILE! main script imports ‘hide.py’ & ‘stocks.csv’
Create this AppleScript(change the path to your path !!)& put it in the script directory so it shows up on the top shelf.
Just click on this button & it will run (use this in place of the Nuitka standalone app workflow shown in the video).
NOTE : Need to enclose path in backslashes if there are spaces in the path.
ALSO NEED TO CREATE A VIRTUAL ENV FOR THIS SCRIPT & ACTIVATE IT AS ABOVE.
For step-by-step instructions on how to create & activate the venv - see PERSONAL/GAMES/JELLYBEAN calculator movie
No longer need to create a Standalone app via Nuitka. You can just link to the Python script via AppleScript.
RUN PYTHON/APPLE SCRIPTS AUTOMATICALLY DAILY
Here is a really cool way to automatically execute a Python script daily at a specific time. this example executes my StockCheckEmail script to email me my portfolio gain/loss 2 hours after the markets open so i can see how things are going & if i need to log in & handle anything.
==========AUTOMATOR==========
Create / New / Application
Add “Run AppleScript”
Paste your Apple Script that you use to execute your Python script here & save to a convenient place.
==========CALENDAR==========
Create / New Event
Starts : For just the setup process - set the time for 2 minutes from now. that way you can “Allow” Permissions now & then it will go off automatically from then on without needing intervention.
Alert : Custom / Open File / Other - Navigate to your Application (you just created above)
Repeat / Custom / Check ON the days you want this to execute
Save & wait for it to execute in 2 minutes.
A popup window should appear asking for your permission to perform the actions in the app.
click “ALLOW”
>> NOW SET THE TIME & DAYS TO WHEN YOU ACTUALLY WANT THIS SCRIPT TO EXECUTE