Skip to content

Instantly share code, notes, and snippets.

@chmouel
Created September 26, 2016 13:16
Show Gist options
  • Save chmouel/634b81869259a175ea667b695f56da23 to your computer and use it in GitHub Desktop.
Save chmouel/634b81869259a175ea667b695f56da23 to your computer and use it in GitHub Desktop.
Watch Stock and notify you when it reach a number or lower to a number. When notified it will create a file in /tmp/.reported.up/down.txt rm it or create a cron that delete the old bugger after certain day
#!/bin/bash
greater= # set to a price i.e: 20
lower= # set to a price i.e: 10
companystock= # set to a stock sympbol i.e: goog, aapl, fb (will only do for one)
[email protected]
function report() {
local mode=$1
local target=$2
local price=$3
local lockfile=/tmp/.reported.${mode}.txt
[[ -e ${lockfile} ]] && exit 0
echo "${price} has becoming ${mode}er than ${target}"|mail -s "${companystock} stock = ${price}" ${email}
touch ${lockfile}
}
function getstock() {
local yahoobase=http://download.finance.yahoo.com/d/quotes.csv?s
local yahooconv="${yahoobase}=USDEUR=X&f=l1"
local stockprice=$(curl -s "${yahoobase}=${companystock}&f=l1"|tr -d '^M')
[[ -n ${greater} ]] && (( $(echo "$stockprice >= ${greater}"|bc -l) )) && report high ${higher} ${stockprice}
[[ -n ${lower} ]] && (( $(echo "$stockprice <= ${lower}"|bc -l) )) && report low ${lower} ${stockprice}
}
getstock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment