Quotes v1.7-1 What is Quotes It is a Perl script that makes use of TCP/IP as underlying protocol to fetch headlines and financial news. Use it to keep track of Linux headlines, monitor your interests in foreign currency and monitor your portafolio of company stocks. All of this from a simple command line interface. Although the script uses HTTP it doesn't fetch all those annoying graphic files that populate these source sites, therefore you get only the information you need without distraction and loss of time. The script had its beginnings in a need I had to know how to write networking code that could work well even behind a proxy/firewall. Since I had a need to track both interests in foreign currency exchange and stocks I decided to add that functionality as well to be accessible at my fingertips without GUI. These days Quotes has found its way to small companies and other interesting prospects appear as well. If you or your company need a custom Quotes application please contact [2]Coralys Technologies, Inc. [3]LinuxBerg (Console/Financial) rating: * * * * A Warning from Cmdr. RegExp Don't be scared! I just want to mention that since there is no agreement between me and the writers of the CGI scripts on Nasdaq and Yahoo, or any other content provider. I had to implement some filtering of HTML (thanks to the great regular expressions) to extract the information from the incoming HTML code. Features The main functionality includes: * Roll your own handler! you can now dynamically add external modules * Basic Authentication handling * Linux headlines from [4]Slashdot (bonus) * Foreign currency exchange and indexes from [5]Yahoo * Stock and index quotations from [6]NASDAQ * Works with a direct connection or via a Proxy/Firewall. * Easy access to lates release of all my software packages using Smart Program Information Files (Smart PIF) (tm). * You can now set it up with [7]QuotesMailer to send you or your pager an update at time intervals (v1.4+). * Supports both system wide (proxy, browser, handlers) and personal (stocks, currencies, browser) resource files. * A handy option to show all the current settings * Enabled HTML output for the Stock part, this allows charting hyperlinks (1.5+) * Useful [8]Quotes applets distributed in a separate package (Financial, Internet, General). [new.gif] * You can also perform currency and stock quotations using the command line (v1.7). [new.gif] Requirements You need Perl 5.x, Quotes Applets and a network connection to the Internet (direct or via proxy/firewall). Configuration The script virtually runs on defaults but it needs to be fed some data for it to give you meaningful information, things like the amount of currency you want to exchange, the source and target currencies, the stock identification (ticker) used by the public company, etc. All of the configuration parameters are specified in a personal resource file ~/.quotesrc and that also includes the Proxy settings. You can also override the built-in and configuration file Proxy settings by using the environment variable export http_proxy="your-proxy.com:8002" Resource files There is a default system wide resource file (/usr/local/lib/Quotes/quotesrc) and optionally a personal resource file. Any directive can be used on any of both types. Both have the same syntax. The only restriction is that at least one resource file must be processed, otherwise we abort due to lack of information. The personal resource file is a hidden file located in your home directory and is interpreted once during start up. All empty lines and lines beginning with the '#' character (without quotes!) are ignored so you can safely add comment lines. The other lines are configuration items and follow the syntax: config_item : value [value-pair] The items currently supported are: Configuration item Example Description setProxy proxy.yeeha.com Proxy hostname, or leave empty otherwise setProxyPort 8002 Port number of Proxy server interval SECONDS Refresh time in seconds when not in one shot setBrowser /usr/bin/netscape The browser executable (not used) setSpifHost panama.iaehv.nl Smart PIF (tm) host setSpifFile ~www/OpenSoft/spif.txt Smart PIF (tm) content file addStock CSCO "Cisco" Stock trade identifier and short description addCurrency 1.0 USD NLG Add exchange rate for "1" US dollar (USD) to Dutch Guilders (NLG) clearCurrency Remove any currencies defined so far clearStock Remove any stock symbols defined so far fromCurrency USD Source currency to use in the exchange. Deprecated toCurrency NLG Target currency to use in the exchange. Deprecated qtyCurrency 100 Amount of currency to exchange (for the query). Deprecated addLibPath /home/grimaldo/PerlLib Add a new library search path without modifying Quotes (v1.3+) addHandler test QuExample Add an external content handler/applet (v1.3+) CAPTION: Resource file options For Stocks the script itself doesn't impose a limit, however the script at Nasdaq imposes a limit of 10 stock tickers per query. If you are trading you surely know your stock tickers, if not visit any stock exchange site (such as NASDAQ) and find out the Stock Ticker names under which the company(ies) trade. For currency exchange symbols visit [9]Yahoo Quotes site because that's my source of quotations. The clearCurrency and clearStock directives are useful only in the personal resource file, for example if the default installation (or your kind sysadmin) already defines some symbols you are not interested in, just clear them all this way. Command line options The program is invoked as: quotes [options] mode The mode is the name of the built-in content handler or the registered name of an external applet. The program supports several command line options to control its behaviour: Short Option Long Option Description Notes -h -help Show help -q -quiet Be quiet, don't show connection status -s -summary Show summaries or extra information -f FILE -rcfile FILE Use an alternate resource file instead of ~/.quotesrc 1.5+ -w -web Use HTML for stock mode 1.5+ CAPTION: Command line options Mode Description currency Get currency exchange quotation stocks Get stock market quotation slashdot Hey bonus! Get Linux headlines spif Use SmartPIF (tm) to find get last-release info CAPTION: Command line mode parameters Make sure not to invoke that Slashdot headlines more often than 30 minutes! otherwise the site owner will get upset, besides twice a day is more than enough!. In addition to the above mentioned modes, you may use the modes defined by external handlers, for example test in the addHandler option mentioned before. Using SmartPIF (tm) you can find out what is the current release of Quotes. And last but not least you can enhance your Quotes installation by also installing the [10]Quotes Applets package. Installation Very simple, unpack the .tar.gz archive gunzip quotes-1.7-1.tar.gz tar xvf quotes-1.7-1.tar gunzip quotes-apps-1.7-1.tar.gz tar xvf quotes-apps-1.7-1.tar cd Quotes-1.7-1 Copy the Quotes scripts to a directory in your PATH such as ~/bin and make sure to change the bang-hash-magic line to point to the location of the Perl interpreter, the default is /usr/bin/perl. mv quotes quotesmailer ~/bin Then copy the sample configuration file to your home directory and adapt it to match your financial interests :). mv sample.quotesrc ~/.quotesrc Even easier, use the makefile for installation, and if you want to install in a place rooted other than /usr/local then use the prefix assignment: make prefix=/opt install It is also possible (and recommended) to download RPM versions. Sample Output The output of the Money Exchange mode looks like this: ********************************************** * C u r r e n c y Q u o t e * * v1.1 * ********************************************** * Local time: 6:39 AM * Market is : Closed. * Exchange : 1 USD = 2.04 NLG @ 2.038800 * Exchange : 1 USD = 12.73 ATS @ 12.73040 * Exchange : 1 NLG = 6.24 ATS @ 6.241310 USD : U.S. Dollar NLG : Dutch Guilder ATS : Austrian Schilling ********************************************** * Quotes (c)2000 D. Emilio Grimaldo Tunon * * Quotation data (c)1998-1999 Yahoo! * ********************************************** Notice that as of v1.4 you can show more than one currency exchange conversion in one go, if more than one are asked for then the network connection status messages are suppresed. The exchange rate (unit price) is now presented along the same Exchange line for each currency. Currency conversions are now done with the addCurrency resource file directive where one indicates (in that order) the quantity, the source and target currencies. The old 'single currency' directives are supported in v1.4 for transition purposes only but will be dropped in the next release!. As of v1.7 it is also possible to perform single currency quotations on the command line: quotes currency 1.50 USD EUR And the Stock quotes output: ********************************************** * S t o c k Q u o t e * ********************************************** * Market : Closed * Date : Jan. 8, 1999 * Last Value Exchange * Symbol Index sale change change volume * ------ --------- -------- -------- ------ ------------ * CSCO Nasdaq-NM $106.687 + 2.31 2.96% 24,028,000 * NSCP Nasdaq-NM $ 61.937 + 1.20 2.36% 5,193,300 * CPWR Nasdaq-NM $ 72.375 + 1.125 4.14% 4,272,300 * SUNW Nasdaq-NM $ 77.375 + 4.375 1.36% 9,700,400 * PHG NYSE $ 66.375 - 0.062 3.26% 456,500 CPWR : "Compuware Corp." CSCO : "Cisco" INDU : "Dow Jones Industrial Average" IXIC : "Nasdaq composite" PHG : "Philips Electronics NV" RHAT : "Red Hat" SPX : "Standard and Poor's 500" SUNW : "Sun Microsystems" ******************************************************************** * Quotes v1.7.1 (c)2000 D. Emilio Grimaldo Tunon * Sponsored by http://www.coralys.com/ * data (c) 2000 NASDAQ Stock Market and Bridge Information Systems ******************************************************************** As of v1.7 it is also possible to perform multiple stock quotations on the command line: quotes stocks BEOS BSQR RHAT And the Slashdot headlines: Type Author Rsp. Title ---------------- ------------ ---- ------------------------------ Movies CmdrTaco (166) Review:Star Trek Insurrection Science Hemos (27) De-coding Worm DNA Games CmdrTaco (16) from Pong to Nintendo 64 News JonKatz (196) Impeachment and the Internet Science Hemos (71) More Mars Missions Linux Hemos (14) Acer plans Linux server for educational mark et Christmas Cheer CmdrTaco (50) Church of Mentos News Hemos (8) MP3 Conference Announcement Netscape CmdrTaco (19) CBS Article on Netscape open source success GNOME CmdrTaco (262) New Gnome Eyecandy News Hemos (135) Car Alarm Flame Thrower Headlines retrieved. And last but not least the Smart PIF output (spif): Loading spif (QuSpif) ********************************************************************** * QuSpif v1.1 * Spif (tm) Didimo Grimaldo ********************************************************************** Package Updates This is : Quotes v1.7.1 Latest : Quotes v1.7-1 Released: 30-Sep-2000 Language: Perl URL : http://www.iae.nl/users/grimaldo/OpenSoft/quotes.shtml FTP : ftp://ftp.iae.nl/pub/users/grimaldo/ FTP : ftp://coralys.com/pub/free/ ---------------------------------------------------------------------- ******************************************************************** * Quotes v1.7.1 (c)2000 D. Emilio Grimaldo Tunon * Sponsored by http://www.coralys.com/ ******************************************************************** QuSpif module ended External Content Handlers (Applets) Since some users have expressed a wish for adding other content providers, and considering I can't possibly spend my time keeping up with Yahoo, Nasdaq, Slashdot and similar content providers, I have enhanced Quotes so that it is now possible (v1.3+) to define your own content handler. This is what you will need: * Proficiency in Perl Regular Expressions, the time you spend learning it will be well worth it!. * Add the necessary entries to your resource file * Write a Perl module that implements the required methods.On v1.5 and v1.7 the API was enhanced! Now let's assume we want to add a content handler named QuExample which should be invoked whenever you invoke Quotes with the test mode as in: quotes test All other options are available as well for your handler. These external content handlers are only loaded if that mode is selected in the Quotes command line!. Since you will most likely add your own Perl modules somewhere else rather than in the Perl standard library directory, you need to tell Quotes which directory this is by adding a line to your resource file, for example: addLibPath /home/grimaldo/PerlLib That makes /home/grimaldo/PerlLib part of the Perl library search path. Your external handler should be located there. This directive must be specified before dynamically adding any external handler!. For our module QuExample which is to be invoked with the test mode, we would need to add this entry to the resource file: addHandler test QuExample The 1st and 2nd parameters are arbitrary, and you can add as many handlers as you wish. The restrictions are that the 1st parameter (test) becomes the Quotes mode to be recognized on the command line and that the 2nd parameter (QuExample) is the name of the module where the external handler is implemented, in this case /home/grimaldo/PerlLib/QuExample.pm. Do notice that the '.pm' extension is not specified in the addHandler directive!. To make things easy, I have provided this example in the distribution. The external handler must be a Perl module that must implement three methods: ModuleNameSetRequest(), ModuleNameSetOptions() and ModuleNameDecode(). External Handler Methods The methods that must be implemented by your external handler have a name prefixed with the module name, in this example these would be QuExampleSetRequest and QuExampleDecode. Please note that these methods are only invoked if the corresponding mode has been selected on the command line. The required [11]Quotes Applets are distributed separately. If you need a custom applet done for you please contact [12]Coralys Consulting. Qu*SetRequest() The SetRequest method is invoked by Quotes to get the hostname of the content provider (eventually including the ':port' part), and the file location. For this we use scalar references. The file part does not include the protocol specification (http://). For more details see the example provided in the distribution. After this method is invoked by Quotes, Quotes will automatically establish the network connection, handle the HTTP response possibly including authentication and fetch the contents. Prototype: *SetRequest(\$host, \$file); As of v1.7 this method must return a value as follows: 0 : no more work to do 1 : will do it just once >=2 : loop execution until I say I'm done Qu*SetOptions() This method was added in v1.5 to allow passing command line parameters to the external applets as described in the [13]Applet documentation page. SetOptions is called before SetRequest and is invoked if and only if there are arguments left in @ARGV, that is arguments that are not consumed by the core Quotes package. This method takes no parameters, it is expected to read its options from @ARGV, something like this: &main::GetOptions('h|help' => \$optHelp); Prototype: *SetOptions(); Qu*Decode() The Decode method is invoked by Quotes once the contents have been fetched from the remote location. Here you need to use your own Perl Regular Expression wizardry to parse the HTML and generate your output. This method is passed two arrays (again by reference), one containing the HTTP headers in case you need to use anything from there, and another array containing the body. Prototype: *Decode(\@headers, \@body); Basic Authentication Again some users expressed an interest in having authentication supported. As of version 1.3 Quotes supports the Basic Authentication protocol as specified in the HTTP standard. It will respond to the challenge by prompting the user for username/password (interactive) and sending back the authorization to the server. QuotesMailer Obviously I have been using this quite a lot, so I decided to automate it even further by adding mail capabilities. QuotesMailer uses sendmail or any delivery agent to send the data you have requested. I have setup QuotesMailer in a crontab so that every morning it fetches the stock information, the linux headlines and the currency exchange rates I am interested in, and have them mailed to me. To make it flexible it reads the email address from a separate file (and not the resource file) and there is one file for each (stock, news, currency). In fact, you can define different (and as many as you want) email addresses so you can keep yourself informed on any of your email addresses. Some users use this to send stock data to their pagers. Configuring QuotesMailer You only need to adapt the stock-list, money-list, news-list, stock-w-list entries in the configuration section of the script. Those are files containing the email address(es) for each of the modules. You may also need to adapt the quotes-bin entry to point to the Quotes script, preferably with the "quiet" option. The same applies to the mail-bin entry which points to the mail delivery agent and its options, the data is piped in to that agent after it is fetched from the net. QuotesMailer Command line options Short Option Long Option Description -m -money Fetch and mail Currency exchange data -s -stocks Fetch and mail Stock quotations -n -news Fetch and mail Linux headlines -h -help Help -t -test Address Fetch and pretend to mail to Address CAPTION: QuotesMailer Command line options On v1.5 of Quotes a simple HTML output was implemented for the stock option (-stock). This is very useful if your mail user agent (the client program) is HTML enabled (Microsoft Outlook, Netscape). This feature implements links so that from the email you can simply click and get immediate stock charting capabilities!. For this you just need to add -web to the stock option command, for example my cronntab looks like this: 00 08 * * Mon-Fri /usr/local/bin/quotesmailer -stocks -web Do notice however that in this situation the email address(es) is obtained from the list setting given in the stock-w-list configuration setting. Future directions Well if the script breaks due to a change of file formats please tell me, if you have a fix please do tell me as well. If you find other sources of information that are less format-dependent (plain-text feed) I would like to know too!. If you like the script and find it useful it would be very nice if you send me a nice postcard from the place you live (I collect postcards), and make sure to write something in the back!. Didimo Emilio Grimaldo T. Apartado 6-472 El Dorado, Panama PANAMA Copyrights * Quotes and SPif are copyright ©1998-2000 Dídimo Emilio Grimaldo Tuñón. * Slashes.pl copyright ©1998 Alex Shnit. * Foreign currency quotation data copyright ©1998-2000 Yahoo!. * Stock quotation data copyright ©1998-2000 Nasdaq Stock Market. Suggestions and Problems Please use the [14]mail applet and select the appropriate subject. if that still does not work then try the email address on the distribution (I am sick of having my email address harvested from the web by spammers). Thanks for your understanding. Download The latest version is available from my main FTP site FTP1 : [15]Quotes v1.7-1 FTP2 : [16]Quotes v1.7-1 Email: grimaldo@panama.iaehv.nl URL: [18]http://www.iae.nl/users/grimaldo/OpenSoft/ Don't forget to get the [19]Applets as well for a more enjoyable experience!. CAPTION: Release History Version Date Notes 1.1-0 13-Dec-1998 First release 1.2-0 17-Jan-1999 Nasdaq decoder update 1.3-0 07-Feb-1999 Nasdaq update, Basic authentication, External handlers 1.4-0 11-Apr-1999 Nasdaq update, multiple currencies, QuotesMailer 1.5-1 19-Nov-1999 Nasdaq update. New applets. API changed. Minor fixes. 1.5-2 02-Feb-2000 Nasdaq update. Minor fixes. 1.6-1 06-Jun-2000 Nasdaq update. Minor fixes. 1.7-1 30-Sep-2000 Minor fixes. Updated modules, Major rewrite. Mailing List If you are interested please join the new mailing list (Feb. 2000). It is not high traffic but once subscribed you will enjoy quick patches and be the first to hear about newer versions. Subscribe to Ct-Quotes Enter your e-mail address: _____________________ Click here to join ct-quotes [20]Ct-Quotes archive. A group hosted by [21]eGroups.com _________________________________________________________________ [22]Site [23]My Panama site ©1995-1999 [24]D. Emilio Grimaldo Tuñón All Rights Reserved _________________________________________________________________ References 1. http://coralys.com/ 2. http://www.coralys.com/ctmail.php3?mode=show&to=info&subject=Quotes 3. http://www.linuxberg.com/ 4. http://slashdot.org/ 5. http://quote.yahoo.com/ 6. http://www.nasdaq.com/ 7. http://home.iaehv.nl/users/grimaldo/OpenSoft/quotes.shtml#QuotesMailer 8. http://home.iaehv.nl/users/grimaldo/OpenSoft/quotesapps.shtml 9. http://quote.yahoo.com/ 10. http://home.iaehv.nl/users/grimaldo/OpenSoft/quotesapps.shtml 11. http://home.iaehv.nl/users/grimaldo/OpenSoft/quotesapps.shtml 12. http://www.coralys.com/ 13. http://home.iaehv.nl/users/grimaldo/OpenSoft/quotesapps.shtml 14. http://home.iaehv.nl/users/grimaldo/mailer.shtml 15. ftp://ftp.iae.nl/pub/users/grimaldo/ 16. ftp://coralys.com/pub/free/ 17. http://home.iaehv.nl/users/grimaldo/mailer.shtml 18. http://www.iae.nl/users/grimaldo/OpenSoft/ 19. http://home.iaehv.nl/users/grimaldo/OpenSoft/quotesapps.shtml 20. http://www.egroups.com/group/ct-quotes/ 21. http://www.egroups.com/ 22. http://home.iaehv.nl/users/grimaldo/site.html 23. http://home.iaehv.nl/users/grimaldo/home.html 24. http://home.iaehv.nl/users/grimaldo/mailer.shtml