Created
July 22, 2020 07:50
-
-
Save izikeros/3d4af369de39c2419f47163b4f694bcd to your computer and use it in GitHub Desktop.
Get stock data from bankier.pl, supports multiple tickers at once | Notowania giełdowe GPW | CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# bankier.sh | |
# Getting stock data from bankier.pl | |
# | |
# usage: | |
# ./bankier.sh ticker | |
# sample tickers: | |
# WIG | |
# WIG20 | |
# mWIG40 | |
# sWIG80 | |
# | |
# sample usage: | |
# ./bankier.sh WIG20 JSW mWIG40 | |
# | |
# author: Krystian Safjan ([email protected]) | |
# Licence MIT | |
set -e | |
LANG=C | |
LC_NUMERIC=C | |
SYMBOLS=("$@") | |
symbols=$(IFS=,; echo "${SYMBOLS[*]}") | |
usage="Usage $0 TICKER" | |
if [ -z "$SYMBOLS" ]; then | |
echo $usage | |
exit | |
fi | |
# Text color variables | |
txtbld=$(tput bold) # Bold | |
red=$(tput setaf 1) | |
green=$(tput setaf 2) | |
white=$(tput setaf 7) | |
txtrst=$(tput sgr0) # Reset | |
OUTPUT='' | |
S=' ' | |
for symbol in $(IFS=' '; echo "${SYMBOLS[*]}" | tr '[:lower:]' '[:upper:]'); do | |
raw=$(wget -qO- https://www.bankier.pl/inwestowanie/profile/quote.html\?symbol\=$symbol | grep -A4 'div class="right textNowrap"') | |
vals=$(echo $raw | sed -e 's/<[^>]*>//g' | sed -e 's/ //g'| sed '/^\s*$/d' | sed 's/ zł/zł/g') | |
val=$(echo $vals | cut -d' ' -f1) | |
percent=$(echo $vals | cut -d' ' -f2) | |
change=$(echo $vals | cut -d' ' -f3) | |
# set color | |
color=$white | |
if echo $raw | grep -q "change up"; then | |
color=$green | |
fi | |
if echo $raw | grep -q "change down"; then | |
color=$red | |
fi | |
OUTPUT="$OUTPUT$txtbld$symbol$txtrst$S$color$val$S$color$percent$txtrst\n" | |
done | |
echo -e $OUTPUT | column -t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment