stock ticker
This commit is contained in:
parent
8ae305e070
commit
1b5d609fb1
2 changed files with 46 additions and 0 deletions
|
|
@ -5,6 +5,11 @@
|
||||||
#interval=3600
|
#interval=3600
|
||||||
#color=#A4C2F4
|
#color=#A4C2F4
|
||||||
|
|
||||||
|
[stock]
|
||||||
|
command=/home/dominic/.config/i3blocks/stock_ticker.py
|
||||||
|
interval=10
|
||||||
|
label=
|
||||||
|
|
||||||
[cpu]
|
[cpu]
|
||||||
command=cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS="" '{printf "%.2f%\n", ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'
|
command=cat <(grep 'cpu ' /proc/stat) <(sleep 1 && grep 'cpu ' /proc/stat) | awk -v RS="" '{printf "%.2f%\n", ($13-$2+$15-$4)*100/($13-$2+$15-$4+$16-$5)}'
|
||||||
interval=3
|
interval=3
|
||||||
|
|
|
||||||
41
.config/i3blocks/stock_ticker.py
Executable file
41
.config/i3blocks/stock_ticker.py
Executable file
|
|
@ -0,0 +1,41 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
'''
|
||||||
|
HOW THIS WORKS:
|
||||||
|
- Install and set up ticker, the linux cli tool to track stock: https://github.com/achannarasappa/ticker
|
||||||
|
- ticker config needs to contain lots, you can just fake the quantity and price...
|
||||||
|
- create a cron job that runs this command:
|
||||||
|
ticker --config=./.ticker.yaml print --format=csv | awk -vFPAT='([^,]*)|("[^"]+")' -vOFS=, '{print $2 " " $3}' | tail -n +2 > /tmp/stock_ticker
|
||||||
|
- make sure that file exists, then run this script..
|
||||||
|
'''
|
||||||
|
import os
|
||||||
|
|
||||||
|
STOCK_TICKER_POSITION_PATH = '/tmp/stock_ticker_position'
|
||||||
|
STOCK_TICKER_PATH = '/tmp/stock_ticker'
|
||||||
|
STOCK_TICKER_POSITION = 0
|
||||||
|
STOCK_TICKER_RESET = False
|
||||||
|
STOCK_TICKER_LINE_COUNT = 0
|
||||||
|
|
||||||
|
if not os.path.exists(STOCK_TICKER_POSITION_PATH):
|
||||||
|
with open(STOCK_TICKER_POSITION_PATH, 'w+') as f:
|
||||||
|
STOCK_TICKER_RESET = True
|
||||||
|
STOCK_TICKER_POSITION = 0
|
||||||
|
f.write('0')
|
||||||
|
|
||||||
|
if not STOCK_TICKER_RESET:
|
||||||
|
with open(STOCK_TICKER_POSITION_PATH, 'r') as f:
|
||||||
|
STOCK_TICKER_POSITION = int(f.readline())
|
||||||
|
|
||||||
|
with open(STOCK_TICKER_PATH, 'r') as f:
|
||||||
|
data = f.readlines()
|
||||||
|
STOCK_TICKER_LINE_COUNT = len(data) - 2
|
||||||
|
|
||||||
|
print(data[STOCK_TICKER_POSITION])
|
||||||
|
|
||||||
|
with open(STOCK_TICKER_POSITION_PATH, 'w+') as f:
|
||||||
|
if STOCK_TICKER_POSITION != None:
|
||||||
|
if STOCK_TICKER_POSITION + 1 <= STOCK_TICKER_LINE_COUNT:
|
||||||
|
f.write(str(STOCK_TICKER_POSITION + 1))
|
||||||
|
else:
|
||||||
|
f.write(str(0))
|
||||||
|
else:
|
||||||
|
f.write(str(0))
|
||||||
Loading…
Reference in a new issue