oh this one... I think I'm starting to have too many things on my desktop...
its my school schedule. so I just took a print screen of it, erased all the white in preview (instant alpha) and put some colors around the different classes. I had fun making it!![]()
# STOCK DATA GRABBER - VERSION 3
# ROBERT WOLTERMAN - 2011
# PULLS DATA FROM A LIST OF STOCKS FOR EASIER USE IN GEEKTOOL
# ORIGINAL WEB PAGE PARSING FOUND ON MACRUMERS.COM FORUM
# CHANGELOG
# 14 APRIL 2011:
# - UPDATED THE FILE PATHS TO /tmp INSTEAD OF /tmp/geektool
# 11 APRIL 2011:
# - ADDED ABILITY TO GET CURRENCY EXCHANGE INFORMATION FROM GOOGLE FINANCE
# THIS CAUSED A CHANGE IN THE FLAT TEXT FILE TO DENOTE PARSING OPTION
# 10 APRIL 2011:
# - PYHON PORT
# - UPDATED REGEX FOR COMPID AS GOOGLE CHANGED THE BACKEND TO THE WEBPAGE
# - ADDED CODE TO RESET THE TERMINAL OUTPUT TO NORMAL ON NO CHANGED STOCKS WHEN USING COLOR OUTPUT
import os, sys, subprocess, re
def regexNormal(mstr,lines):
# THIS WORKS FOR EVERYTHING EXCEPT FOR THE BIG MARKETS
mat = re.search(mstr,lines)
# GET THE DATA WE NEED
mline = mat.group(0).split('{')[1].split('}],t')[0]
mlines = mline.split(',')
url2 = mlines[0].split(':')[1]
name = mlines[1].split(':')[1].split('"')[1]
cp = float(mlines[2].split(':')[1].split('"')[1])
p = float(mlines[3].split(':')[1].split('"')[1])
cid = mlines[4].split(':')[1]
c = p * (cp/100)
# RETURN DATA
return p, c, cp
def regexOther(opt,lines):
# GET COMPANY ID
m1 = re.search("setCompanyId.*;",lines)
cid = m1.group(0).split("(")[1].split(");")[0]
# GET PRICE
if opt == "m" or opt == "s":
m2 = re.search("ref_"+str(cid)+"_l.*",lines)
p = m2.group(0).split(">")[1].split("<")[0]
elif opt == "c":
m2 = re.search("bld.*",lines)
p = m2.group(0).split(">")[1].split(" ")[0]
# GET CHANGE
m3 = re.search("ref_"+str(cid)+"_c.*",lines)
c = m3.group(0).split(">")[1].split("<")[0]
# GET CHANGE PERCENT
m4 = re.search("ref_"+str(cid)+"_cp.*",lines)
cp = m4.group(0).split(">")[1].split("<")[0]
return p, c, cp
# OUTPTYPE OF -c IS FOR COLORED OUTPUT
# OUTPTYPE OF -n IS FOR NONCOLORED OUTPUT
OUTPTYPE = sys.argv[1]
# SETS UP THE VARIABLE FOR THE TICKER FILE
TICKFILE = sys.argv[2]
if __name__ == "__main__":
# SET UP LISTS TO HOLD DATA
symlist = []
plist = []
cplist = []
clist = []
# CHECK TO SEE IF WE CAN PING GOOGLE
retcode = subprocess.call("ping -c 1 www.google.com",
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# IF retcode IS ZERO, WE CONTINUE, ELSE DO NOTHING
if retcode == 0:
# OPEN STOCKLIST FILE FOR WRITE (WILL DESTROY PREVIOUS CONTENTS
#fout.open("/tmp/stocklist","w")
# OPEN THE TICKERFILE
fin = open(TICKFILE)
# READ THE TICKFILE LINES
lines = fin.readlines()
# CLOSE TICKERFILE FILE
fin.close()
# LOOP THROUGH THE LINES AND GET THE STOCK VALUES
for line in lines:
tmp = line.split("\n")[0]
if tmp != "":
tmp = tmp.split(" ")
opt = tmp[0].lower()
if opt == "m" or opt == "s":
mkt = tmp[1]
sym = tmp[2]
elif opt == "c":
sym = tmp[1]
symlist.append(sym)
# FIGURE OUT IF WE ARE DOING A MARKET GRAB OR A STOCK GRAB
if opt == "m":
url = "http://www.google.com/finance?q="+mkt
elif opt == "c":
url = "http://www.google.com/finance?q="+sym
elif opt == "s":
url = "http://www.google.com/finance?q="+mkt+":"+sym
# NOW THAT WE HAVE THE URL, GET THE STOCK FILE
sfile = "%s.stock" % sym
cmd = "curl --silent %s > /tmp/geektool/%s.stock" % (url, sym)
# GET THE STOCK PAGE
ret = subprocess.call(cmd,shell=True,stdout=subprocess.PIPE)
# LOOK THROUGH THE STOCK FILE TO GET THE NEEDED DATA
fin = open("/tmp/"+sfile)
lines = fin.read()
fin.close()
# DO OUR REGULAR EXPRESSIONS
p,c,cp = regexOther(opt,lines)
# APPEND DATA TO THE LISTS
plist.append(p)
clist.append(c)
cplist.append(cp)
# LETS DO OUR PRINTING
# NORMAL
if OUTPTYPE == "-n":
for i in xrange(len(symlist)):
print "",symlist[i].ljust(6), plist[i].rjust(10), clist[i].rjust(9), cplist[i].rjust(9)
# COLORS
elif OUTPTYPE == "-c":
for i in xrange(len(symlist)):
if float(clist[i]) < 0.00:
print '\033[42;1;37m',symlist[i].ljust(6), plist[i].rjust(10), clist[i].rjust(9), cplist[i].rjust(9)
elif float(clist[i]) > 0.00:
print '\033[41;1;37m',symlist[i].ljust(6), plist[i].rjust(10), clist[i].rjust(9), cplist[i].rjust(9)
elif float(clist[i]) == 0.00:
# RESET THE COMMAND LINE
subprocess.call("tput sgr0",shell=True)
print "",symlist[i].ljust(6), plist[i].rjust(10), clist[i].rjust(9), cplist[i].rjust(9)
# RESET THE COMMAND LINE AGAIN
subprocess.call("tput sgr0",shell=True)
else:
print "No Internet Connection"
m INDEXNASDAQ:.IXIC NASDAQ
m INDEXDJX:.DJI DOW
s NYSE COL
s NYSE UA
s NYSE EK
s NYSE SHS
s NYSE BA
s NYSE LMT
s NYSE NOC
s NYSE GD
s NYSE RTN
s NYSE USG
s NYSE HON
s NYSE CRS
s NYSE S
s NYSE PEP
c EURGBP
python ~/bin/geektool/tickerv3.py -c ~/bin/geektool/tickerlist.txt
python ~/bin/geektool/tickerv3.py -n ~/bin/geektool/tickerlist.txt
Hey guys,
Anyone know why the following script won't output anything?
curl http://www.google.com/finance?q=EURGBP | sed -n '/price-panel style/,/ Close/p' | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'| sed '/^$/d' | sed -e '$!N;s/\n/ /' -e '$!N;s/\n/ /' | head -1 | sed 's/^/DOW: /g'
It works really well for stocks and indexes but doesn't seem to do the trick for currencies…
Also anyone know how to make the following show in the same format as the Google quotes? ie: NAME: CurrentPrice Change (PercentageChange)
http://finance.yahoo.com/q?s=GCJ11.CMX
Would be really grateful for any help!
The reason the command line regex won't work for currency is the data that it is trying to find does not exist in the file. I just updated my Python stock ticker list to work with currency, will update the post above yours with the new code; check there if you want that solution for the time being.
Code Updated in Post 2909
As for the Gold Futures at Yahoo, I'm looking into a solution for that which is able to be embedded into my ticker program. The difficult thing about adding Yahoo support is that I'll have to add support for all Yahoo finance data to make it fair for people who may not want to use Google.
# OPEN STOCKLIST FILE FOR WRITE (WILL DESTROY PREVIOUS CONTENTS
#fout.open("/tmp/geektool/stocklist","w")
# OPEN THE TICKERFILE
fin = open(TICKFILE)
I'm terribly sorry if this has been asked before and I missed it -
I'm new to GeekTools, and although I've been having lots of fun with it, I wonder if there is a way I can "lock it" to a specific Space.
Amazed by everything I've seen so far,
Zetthy\\
really cool program you just made there. but it doesnt work for me.
the problem is at line 87 around:
gives me this when I run it into terminal:Code:# OPEN STOCKLIST FILE FOR WRITE (WILL DESTROY PREVIOUS CONTENTS #fout.open("/tmp/geektool/stocklist","w") # OPEN THE TICKERFILE fin = open(TICKFILE)
IOError: [Errno 2] No such file or directory: '~/.Geektool/tickerlist.txt'
but im sure everything is where its suppose to be.
any clue?
[20:07:27][taco@elcomputer]$ pwd
/Users/taco/bin/geektool
[20:49:21][taco@elcomputer]$ cd ../..
[20:49:23][taco@elcomputer]$ ls
Applications Library Public personal
Desktop Movies Quartz-ImageUnits-GettingStarted.pdf projects
Documents Music Sites utility
Downloads Pictures bin
[20:49:24][taco@elcomputer]$ mkdir .Geektool
[20:49:27][taco@elcomputer]$ cp ~/bin/geektool/tickerlist.txt ./.Geektool/
[20:49:38][taco@elcomputer]$ python ~/bin/geektool/tickerv3.py ~/.Geektool/tickerlist.txt
Traceback (most recent call last):
File "/Users/taco/bin/geektool/tickerv3.py", line 64, in <module>
TICKFILE = sys.argv[2]
IndexError: list index out of range
[20:49:57][taco@elcomputer]$ python ~/bin/geektool/tickerv3.py -n ~/.Geektool/tickerlist.txt
NASDAQ 2,744.79 -26.72 (-0.96%)
DOW 12,263.58 -117.53 (-0.95%)
COL 63.49 -0.63 (-0.98%)
UA 73.97 +0.68 (0.93%)
EK 3.30 0.00 (0.00%)
SHS 51.17 -1.52 (-2.88%)
BA 73.08 -0.68 (-0.92%)
LMT 80.37 -0.14 (-0.17%)
NOC 62.84 -0.11 (-0.17%)
GD 72.92 -0.83 (-1.13%)
RTN 50.14 -0.58 (-1.14%)
USG 16.34 +0.22 (1.36%)
HON 57.53 -0.73 (-1.25%)
CRS 40.69 -0.29 (-0.71%)
S 4.80 +0.09 (1.91%)
PEP 66.57 +0.53 (0.80%)
[20:52:17][taco@elcomputer]$
Interesting issue brenm666. I just recreated your directory structure and ran my script in the command line and got the proper output. Here is my command history:
Code:[20:07:27][taco@elcomputer]$ pwd /Users/taco/bin/geektool [20:49:21][taco@elcomputer]$ cd ../.. [20:49:23][taco@elcomputer]$ ls Applications Library Public personal Desktop Movies Quartz-ImageUnits-GettingStarted.pdf projects Documents Music Sites utility Downloads Pictures bin [20:49:24][taco@elcomputer]$ mkdir .Geektool [20:49:27][taco@elcomputer]$ cp ~/bin/geektool/tickerlist.txt ./.Geektool/ [20:49:38][taco@elcomputer]$ python ~/bin/geektool/tickerv3.py ~/.Geektool/tickerlist.txt Traceback (most recent call last): File "/Users/taco/bin/geektool/tickerv3.py", line 64, in <module> TICKFILE = sys.argv[2] IndexError: list index out of range [20:49:57][taco@elcomputer]$ python ~/bin/geektool/tickerv3.py -n ~/.Geektool/tickerlist.txt NASDAQ 2,744.79 -26.72 (-0.96%) DOW 12,263.58 -117.53 (-0.95%) COL 63.49 -0.63 (-0.98%) UA 73.97 +0.68 (0.93%) EK 3.30 0.00 (0.00%) SHS 51.17 -1.52 (-2.88%) BA 73.08 -0.68 (-0.92%) LMT 80.37 -0.14 (-0.17%) NOC 62.84 -0.11 (-0.17%) GD 72.92 -0.83 (-1.13%) RTN 50.14 -0.58 (-1.14%) USG 16.34 +0.22 (1.36%) HON 57.53 -0.73 (-1.25%) CRS 40.69 -0.29 (-0.71%) S 4.80 +0.09 (1.91%) PEP 66.57 +0.53 (0.80%) [20:52:17][taco@elcomputer]$
Disregard my error in typing my own command, it's easy to forget the color option.
Every time I've seen IOError 2 in Python, I've always not had the file where I thought it was supposed to be.
Can you post the results of ls of your ~/.Geektool directory? Can you post the actual command you are running?
MacBook-Pro:~ brendan$ pwd
/Users/brendan
MacBook-Pro:~ brendan$ cd .Geektool/
MacBook-Pro:.Geektool brendan$ ls
Horaire H2011 B.png iTunes.scpt tickerv3.py
gen_news_grabber.py refresh.scpt
iTunes extra.scpt tickerlist.txt
MacBook-Pro:.Geektool brendan$ python ~/.Geektool/tickerv3.py -n ~/.Geektool/tickerlist.txt
/bin/sh: /tmp/geektool/NASDAQ.stock: No such file or directory
Traceback (most recent call last):
File "/Users/brendan/.Geektool/tickerv3.py", line 124, in <module>
fin = open("/tmp/geektool/"+sfile)
IOError: [Errno 2] No such file or directory: '/tmp/geektool/NASDAQ.stock'
well, here's what I have here.
hmm. weird. new error.Code:MacBook-Pro:~ brendan$ pwd /Users/brendan MacBook-Pro:~ brendan$ cd .Geektool/ MacBook-Pro:.Geektool brendan$ ls Horaire H2011 B.png iTunes.scpt tickerv3.py gen_news_grabber.py refresh.scpt iTunes extra.scpt tickerlist.txt MacBook-Pro:.Geektool brendan$ python ~/.Geektool/tickerv3.py -n ~/.Geektool/tickerlist.txt /bin/sh: /tmp/geektool/NASDAQ.stock: No such file or directory Traceback (most recent call last): File "/Users/brendan/.Geektool/tickerv3.py", line 124, in <module> fin = open("/tmp/geektool/"+sfile) IOError: [Errno 2] No such file or directory: '/tmp/geektool/NASDAQ.stock'
thanks for the help anyway!![]()
perfect. works like a charm.I have a feeling that the issue is there is no /tmp/geektool folder.
I have seen an issue where the geektool folder that you need to create in /tmp goes away when you power cycle the computer. I ended up putting some code in ~/.profile to prevent this from happening, but if you want to change the path in the python program from /tmp/geektool to /tmp, things might work better.
perfect. works like a charm.
except (I'm starting to annoy you dont I...) when I use the color (-c) code, a weird "n" appears before the first line, when I use it with geektool. works perfectly fine in terminal.
I dont really mind, but some people might!![]()
Hello, I'm a bit new around here. I don't know if this has been addressed b4. I'm having a bit of problem with Geektool. the problem is that it's a bit slow to respond. Whenever i need to move geeklets around, it takes a longer time than usual to acknowledge that i moved the geeklet around. Or sometimes it fails to recognize that i have clicked on another geeklet to focus on it. When i first installed Geektool and started making geeklets, they were always instantly responsive and when i dragged them to rearrange them, they complied, but now it takes a while and i don't get desired results. Is there any fix to this?
try restarting geektool, or even your computer. should run smoother after.
just registered to post a fast screenshot of my desktop
[url=http://img535.imageshack.us/img535/6411/geektool.jpg]Image[/URL]![]()
DAY=""; HRS=""; MIN=""
VAR=`uptime | sed 's/^.*up *//;s/, [0-9]* user.*$//'`
if [[ "$VAR" =~ "days" ]];then
DAY=`echo "$VAR" | awk '{print $1,$2}'`
VAR=`echo "$VAR" | sed 's/^.*day[s], //'`
fi
if [[ "$VAR" =~ ":" ]];then
HRS=`echo "$VAR" | sed 's/\([0-9]*\):.*/\1/'`
MIN=`echo "$VAR" | sed 's/^.*://;s/^0//'`
[[ $MIN = 1 ]] && MIN="$MIN minute" || MIN="$MIN minutes"
[[ $HRS = 1 ]] && HRS="$HRS hour, " || HRS="$HRS hours, "
VAR="$HRS$MIN"
else
VAR=`echo "$VAR" | sed 's/hr/hour/;s/hrs/hours/;s/min/minute/;s/mins/minutes/;s/secs/seconds/'`
fi
echo "Uptime: $DAY$VAR"
Thanks for the reply. I'm using 3 at the moment. Do you know an answer for my other question, after restarting my iMac my scripts no longer show, and I have to go back into GeekTool to refresh and get them working again, am I going to have to do this all the time or is there an option to make them work all the time?
![]()