summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Stadler <patrick.stadler@gmail.com>2023-04-21 21:27:29 +0200
committerPatrick Stadler <patrick.stadler@gmail.com>2023-04-21 21:27:29 +0200
commitaf7a595177cf999a4d5f2fca842030abab768156 (patch)
treef2d5b9b3e34fe5769ce2b621a3a81849bc352d57
parent678f8c25e9d950ba244f06be98dae3c10d927345 (diff)
Revert "acquire yahoo finance session (fixes #33) (#35)"
-rw-r--r--README.md2
-rwxr-xr-xticker.sh30
2 files changed, 3 insertions, 29 deletions
diff --git a/README.md b/README.md
index 342cb18..3cbe366 100644
--- a/README.md
+++ b/README.md
@@ -42,8 +42,6 @@ $ watch -n 5 -t -c ./ticker.sh AAPL MSFT GOOG BTC-USD
$ while true; do clear; ./ticker.sh AAPL MSFT GOOG BTC-USD; sleep 5; done
```
-Please note that ticker.sh may require periodic updates of its session with Yahoo Finance. During these instances, the script may take slightly longer to complete.
-
This script works well with [GeekTool](https://www.tynsoe.org/geektool/) and similar software:
```sh
diff --git a/ticker.sh b/ticker.sh
index 3e4caf2..7606940 100755
--- a/ticker.sh
+++ b/ticker.sh
@@ -4,11 +4,6 @@ set -e
LANG=C
LC_NUMERIC=C
-: ${TMPDIR:=/tmp}
-SESSION_DIR="${TMPDIR%/}/ticker.sh-$(whoami)"
-COOKIE_FILE="${SESSION_DIR}/cookies.txt"
-CRUMB_FILE="${SESSION_DIR}/crumb.txt"
-
SYMBOLS=("$@")
if ! $(type jq > /dev/null 2>&1); then
@@ -35,27 +30,8 @@ fi
symbols=$(IFS=,; echo "${SYMBOLS[*]}")
fields=$(IFS=,; echo "${FIELDS[*]}")
-[ ! -d "$SESSION_DIR" ] && mkdir -m 700 "$SESSION_DIR"
-
-preflight () {
- curl --silent --output /dev/null --cookie-jar "$COOKIE_FILE" "https://finance.yahoo.com" \
- -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"
- curl --silent -b "$COOKIE_FILE" "https://query1.finance.yahoo.com/v1/test/getcrumb" \
- > "$CRUMB_FILE"
-}
-
-fetch_quotes () {
- curl --silent -b "$COOKIE_FILE" "$API_ENDPOINT&fields=$fields&symbols=$symbols&crumb=$(cat "$CRUMB_FILE")"
-}
-
-[ ! -f "$COOKIE_FILE" -o ! -f "$CRUMB_FILE" ] && preflight
-results=$(fetch_quotes)
-if $(echo "$results" | grep -q '"code":"Unauthorized"'); then
- preflight
- results=$(fetch_quotes)
-fi
-
-results=$(echo $results | jq '.quoteResponse .result')
+results=$(curl --silent "$API_ENDPOINT&fields=$fields&symbols=$symbols" \
+ | jq '.quoteResponse .result')
query () {
echo $results | jq -r ".[] | select(.symbol == \"$1\") | .$2"
@@ -106,4 +82,4 @@ for symbol in $(IFS=' '; echo "${SYMBOLS[*]}" | tr '[:lower:]' '[:upper:]'); do
printf "$color%10.2f%12s$COLOR_RESET" $diff $(printf "(%.2f%%)" $percent)
printf " %s\n" "$nonRegularMarketSign"
fi
-done \ No newline at end of file
+done