m0rin09ma3 myshellv1 20130719-060417


Posted:

Prerequisite

I installed requests and cmd2 modules for this assignment in my 'virt1' environment.

(virt1) $ yolk -l
Python          - 2.7.5        - active development (/usr/lib/python2.7/lib-dynload)
beautifulsoup4  - 4.2.1        - active
cmd2            - 0.6.5.1      - active
lxml            - 3.2.1        - active
pip             - 1.3.1        - active
requests        - 1.2.3        - active
setuptools      - 0.6c11       - active
wsgiref         - 0.1.2        - active development (/usr/lib/python2.7)
yolk            - 0.4.3        - active

$ python myshellv1.py

A link to the source code.

Sample output:

(Cmd) greet
Hi, m0rin09ma3
(Cmd) stock GOOG
910.68

Explanation

In the Application class, there are 2 methods (do_greet() for greeting, do_stock() for getting quotes from specified url)

def do_greet(self, line):
    print "Hi, %s" % os.getlogin()

def do_stock(self, line):
    quote = {'s': line, 'f': 'l1'}
    target_url = 'http://download.finance.yahoo.com/d/quotes.csv'
    r = requests.get(target_url, params=quote)
    #print r.url
    print r.text
Contents © 2013 dgplug - Powered by Nikola
Share
UA-42392315-1