Skip to content

Commit

Permalink
Added crypto and cryptowatch functions
Browse files Browse the repository at this point in the history
  • Loading branch information
eko committed Dec 20, 2017
1 parent 54a2485 commit dc76717
Showing 1 changed file with 43 additions and 5 deletions.
48 changes: 43 additions & 5 deletions .functions
@@ -1,3 +1,9 @@
# Common
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'

# Base64 encode a string
function b64() {
echo -n "$*" | base64
Expand All @@ -7,14 +13,46 @@ function b64decode() {
echo -n "$*" | base64 --decode
}

# Usage: bitcoinalert 9800
function bitcoinalert() {
# Usage: crypto <money> <currency>
function crypto() {
curl -s https://api.cryptonator.com/api/ticker/$1-$2 | jq -r '.ticker .price'
}

# Usage: cryptowatch <money> <currency> [<wallet amount> [<alert amount>]]
function cryptowatch() {
latest=0

while true; do
value=$(bitcoin)
value=$(crypto $1 $2)
current=`printf "%.2f" $(( value ))`
date=$(date "+%H:%M:%S")
operator="${YELLOW}=${NC}"
walletvalue=0

# Find operator
if (( $(echo "$value > $latest" | bc -l) )); then
operator="${GREEN}⬆${NC}"
elif (( $(echo "$value < $latest" | bc -l) )); then
operator="${RED}⬇${NC}"
fi

latest=$value

if (( $(echo "$value > $1" | bc -l) )); then
osascript -e "display notification "$value" with title \"Bitcoin alert\" subtitle \"Current value:\"";
display="$operator | $date | $1: ${YELLOW}$current${NC}"

if [ -n "$3" ]; then
walletvalue=`printf "%.2f" $(( $3 * $value ))`
display="$display | EUR: ${YELLOW}$walletvalue${NC}"
fi

echo $display

# Amount reached? Notify
if [ -n "$4" ] && (( $(echo "$value >= $4" | bc -l) )); then
osascript -e "display notification "$value" with title \"Cryptowatch\" subtitle \"Current value:\""
fi

sleep 15
done
}

Expand Down

0 comments on commit dc76717

Please sign in to comment.