modothprav / automated-portfolio-tracking Goto Github PK
View Code? Open in Web Editor NEWA Java automation project which scrapes transaction data from the New Zealand investing platform - Sharesies and enters it into Yahoo Finance through Selenium
A Java automation project which scrapes transaction data from the New Zealand investing platform - Sharesies and enters it into Yahoo Finance through Selenium
If the program were to be ran in an external machine, it will have to run in headless mode without the GUI. Modify your automation flow accordingly
Website has the feature to track holdings in a portfolio, under the edit portfolio
section, we are presented with a web table in which transactions can be entered. Can be automated with selenuim. Would mean to implement separate classes with all simply wall street pages similar to sharesies pages.
//table[@class='htCore']/tbody/tr[ROW]/td[COL]
Download a version of chromedriver that is compatible with chrome version 98
Similar to Yahoo Finance where entered values were checked and WebDriverWait
was used to confirm performed actions.
The program will not be dealing with older versions of Excel (.xls files)
The transactions will always be entered for the previous month with respect to the time it was triggered.
e.g if the workflow was triggered in June the transactions for May will be entered.
Bash script which determines the full name of the previous month also decrements the Year
if the last month was December
#!/bin/bash
# Get Current Year and Previous Month
YEAR="$(date +%Y)"
export LAST_MONTH="$(date -v-1m +%B)"
# Check if previous month is December by converting
# to numerical form. If it is then decrease year
if [[ $LAST_MONTH == "December" ]]
then
YEAR="$(date -v-1y +%Y)"
fi
echo "Program being run for - $LAST_MONTH $YEAR"
export YEAR
Run command
. ./script.sh
File file = new File(folderPath);
file.mkdirs();
Varying load times seem to easily break the program and need better checks for a greater success rate.
The
chromedriver
already installed in the repo for use will only work on Apple Macs with the m1 chip
The GitHub actions runs on a linux machine hence the appropriate binaries will need to be downloaded. Therefore along with chrome
, chromedriver
will also need to be downloaded.
#!/bin/bash
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
echo "deb http://dl.google.com/linux/chrome/deb/ stable main" | sudo tee -a /etc/apt/sources.list.d/google-chrome.list
sudo apt-get update -qqy
sudo apt-get -qqy install google-chrome-stable
CHROME_VERSION=$(google-chrome-stable --version)
CHROME_FULL_VERSION=${CHROME_VERSION%%.*}
CHROME_MAJOR_VERSION=${CHROME_FULL_VERSION//[!0-9]}
sudo rm /etc/apt/sources.list.d/google-chrome.list
export CHROMEDRIVER_VERSION=`curl -s https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MAJOR_VERSION%%.*}`
curl -L -O "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip"
unzip chromedriver_linux64.zip && chmod +x chromedriver
export CHROMEDRIVER_VERSION=`curl -s https://chromedriver.storage.googleapis.com/LATEST_RELEASE_${CHROME_MAJOR_VERSION%%.*}`
curl -L -O "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip"
unzip chromedriver_linux64.zip && chmod +x chromedriver
chromedriver -version
Script above will install chorme and chromedriver
This way can specify the month and year to run the process through the command line.
mvn compile exec:java -Dexec.mainClass=automate.Automation -Dexec.cleanupDaemonThreads=false
mvn exec:java -Dexec.mainClass=autoamte.Automation -Dexec.cleanupDaemonThreads=false -Dexec.args="Janurary 2022 February 2022"
Use the contains
function in xpath to make it more flexible in the future
XPath = //tag[contains(@attribute, 'value')]
From the Login page onwards the title for all pages loaded after seems to be the same. Improve validation upon page initialization, to distinguish among the different web pages.
Ensure Login credentials aren't accessible.
Another inconsistent check, which sometimes breaks and other times has no problems.
This xpath can be used for initial selection of the stock for the data to be entered
//table/tbody["index"]/tr[2]/td/button
The xpath above will click on the arrow drop-down button for a stock based on the index specified. Once clicked will display another table to then enter the individual transactions for that stock
//table/tbody["stock-row-index"]/tr[3]/td/table/tbody/tr["transaction-index"]/td["transaction-property-index"]
May have to include a step to download chrome if the machine does not have it.
#!/bin/bash
set -ex
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb
steps:
- uses: browser-actions/setup-chrome@latest
- run: chrome --version
with:
chrome-version: beta
on:
schedule:
# Second day of the Month
- cron: 0 0 2 * *
mvn exec:java -Dexec.mainClass=autoamte.Automation -Dexec.cleanupDaemonThreads=false -Dexec.args="Janurary 2022 February 2022"
steps:
- name: "Run Main Process"
run: mvn exec:java -Dexec.mainClass=autoamte.Automation
env:
YAHOO_USERNAME: Pravin
- name: Send mail
uses: dawidd6/action-send-mail@v3
with:
# Required mail server address:
server_address: smtp.gmail.com
# Required mail server port:
server_port: 465
# Optional (recommended): mail server username:
username: ${{secrets.MAIL_USERNAME}}
# Optional (recommended) mail server password:
password: ${{secrets.MAIL_PASSWORD}}
# Required mail subject:
subject: Github Actions job result
# Required recipients' addresses:
to: [email protected],[email protected]
# Required sender full name (address can be skipped):
from: Luke Skywalker # <[email protected]>
# Optional whether this connection use TLS (default is true if server_port is 465)
secure: true
# Optional plain body:
body: Build job of ${{github.repository}} completed successfully!
# Optional HTML body read from file:
html_body: file://README.html
# Optional carbon copy recipients:
cc: [email protected],[email protected]
# Optional blind carbon copy recipients:
bcc: [email protected],[email protected]
# Optional recipient of the email response:
reply_to: [email protected]
# Optional Message ID this message is replying to:
in_reply_to: <[email protected]>
# Optional unsigned/invalid certificates allowance:
ignore_cert: true
# Optional converting Markdown to HTML (set content_type to text/html too):
convert_markdown: true
# Optional attachments:
attachments: attachments.zip,git.diff,./dist/static/*.js
# Optional priority: 'high', 'normal' (default) or 'low'
priority: low
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.