Register
It is currently Thu Oct 30, 2014 8:26 am

stock function - quick quote from the command line


All times are UTC - 6 hours


Post new topic Reply to topic  [ 10 posts ] 
Author Message
 PostPosted: Mon Jan 03, 2011 9:59 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
This function returns a quick realtime quote from the command line.

Code:
stock ()
{
echo -n "${1}: "
lynx -dump http://finance.yahoo.com/q?s=${1} | grep "Real Time" | cut -f2 -d] | sed 's/Real Time//'
}


Top
 Profile WWW  
 PostPosted: Mon Jan 03, 2011 10:43 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
nm... wrote one i like even more now...

Code:
stock ()
{
lynx -dump "http://www.google.com/finance?client=ob&q=${1}" | sed 's/.*']'//' | perl -00ne "print if /Watch this stock/i" | sed 's/Watch this stock//' | sed 's/Disclaimer//' | sed '/^$/d' | sed 's/Currency in USD//'
}


Code:
crouse@archie stock slv

slv
   30.26
   +0.08 (0.27%)
   Real-time:   11:41AM EST

    1. Range 30.14 - 30.44
    2. 52 week 14.37 - 30.44
    3. Open 30.29
    4. Vol / Avg. 9.57M/26.84M
    5. Mkt cap 9.73B
    6. P/E 95.32
    7. Div/yield     -
    8. EPS 0.32
    9. Shares 321.50M
   10. Beta 0.38
   11. Inst. own 25%


Top
 Profile WWW  
 PostPosted: Sun Feb 05, 2012 2:11 pm   

Joined: Sun Jul 17, 2011 4:21 pm
Posts: 6
This looks like a really amazing script. My only problem is that I'm running the Mac OS, not Linux, so I don't have the lynx function. Is there another function that works like lynx and on Macs that can be used as a substitute? Thanks


Top
 Profile  
 PostPosted: Wed Mar 14, 2012 4:14 am   

Joined: Mon Sep 26, 2011 10:17 pm
Posts: 4
chumponimys wrote:
This looks like a really amazing script. My only problem is that I'm running the Mac OS, not Linux, so I don't have the lynx function. Is there another function that works like lynx and on Macs that can be used as a substitute? Thanks

If it has a function to output into formatted text (as opposed to html...) then it should be real easy. Post a "Bash on MacOS" adaptation if you find one. I don't use Mac, but that doesn't mean I lack respect. ;)


Top
 Profile  
 PostPosted: Sat Aug 17, 2013 9:47 am   

Joined: Fri Jul 19, 2013 5:17 pm
Posts: 10
How do I use a text file to input the data?

here is what earlier this week was working for me:

#!/bin/bash

stock ()
{
lynx -dump "http://www.google.com/finance?client=ob&q=${1}" | sed 's/.*']'//' | perl -00ne "print if /Watch this stock/i" | sed 's/Watch this stock//' | sed 's/Disclaimer//' | sed '/^$/d' | sed 's/Currency in USD//' | > /home/user/Desktop/stockquote.txt
}

any ideas why all it issues is a empty file where before it put the output from the script to a file for further parsing.


Top
 Profile  
 PostPosted: Wed Sep 18, 2013 2:49 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
Code:
lynx -dump "http://www.google.com/finance?client=ob&q=${1}" | sed 's/.*']'//' | perl -00ne "print if /Watch this stock/i" | sed 's/Watch this stock//' | sed 's/Disclaimer//' | sed '/^$/d' | sed 's/Currency in USD//' | > /home/user/Desktop/stockquote.txt


should be

Code:
lynx -dump "http://www.google.com/finance?client=ob&q=${1}" | sed 's/.*']'//' | perl -00ne "print if /Watch this stock/i" | sed 's/Watch this stock//' | sed 's/Disclaimer//' | sed '/^$/d' | sed 's/Currency in USD//' > /home/user/Desktop/stockquote.txt


I removed the "|" from right before "> /home/user/Desktop/stockquote.txt"

HTH's.


Top
 Profile WWW  
 PostPosted: Tue Nov 05, 2013 7:19 pm   
User avatar

Joined: Wed Jun 08, 2011 8:27 am
Posts: 189
Location: outer Shpongolia
One sed(1) is enough for this. : -)

Code:
lynx -dump "https://www.google.com/finance?q=$1" | sed -n '/Watch this stock/,/^$/{//d;/Disclaimer/d;s/.*USD//;s/.*]//;p;}'


Top
 Profile  
 PostPosted: Sun Nov 17, 2013 12:21 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
Sure, totally illegible imho too.


Top
 Profile WWW  
 PostPosted: Tue Nov 19, 2013 8:55 am   
Moderator
User avatar

Joined: Thu Oct 11, 2007 7:12 am
Posts: 229
Location: London - UK
crouse wrote:
Sure, totally illegible imho too.


aye, I wonder what answers he'd give to my interview questions, ie could I even understand them heh :)


Top
 Profile  
 PostPosted: Tue Jan 14, 2014 11:27 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
My day job is as a Systems Administrator, so I ALWAYS code for readability and maintainability ...and since it's probably going to be me doing the reading and maintaining... I always choose readability over the cool factor ;) Also lots and lots and LOTS of comments. Saves time/headaches when you can least afford either. Just mho though.

One of the quotes I consistently repeat and use, comes from a perl book...


Always code as if the guy who ends up maintaining your code
will be a violent psychopath who knows where you live.


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP