.. link: http://dgplug.org/summertraining/2013/posts/devyani-divs-myshellv1-20130718-204314.html .. description: .. tags: .. date: 2013/07/18 20:43:15 .. title: Devyani-Divs myshellv1 20130718-204314 .. slug: devyani-divs-myshellv1-20130718-204314 Myshellv1 ========= Problem: ======== Write a program that constitutes the following two commands: 1)greet : which will say "Hi" to the user. 2)stock : which will print the cureent stock value. #The above commands are to be executed using the requests library. Program-Code ============ .. code:: python from cmd2 import Cmd from getpass import getuser import sys import requests __version__ = '0.1' class Application(Cmd): """ The main Application class """ def __init__(self): Cmd.__init__(self) def do_hello(self, line): print "Hello:", line def do_greet(self,line): print "Hi %s :)" %(getuser()) def do_stock(self,line): r=requests.get('http://download.finance.yahoo.com/d/quote.csv?s='+line+'&f=l1') data=r.text print data if __name__ == '__main__': app = Application() app.cmdloop() Explanation of the code ======================= In the code, the greet function uses the getuser() in order to get the name of the user, and displays "Hi " as output. And the stock function uses the requests.get() function to get the latest value of the stock-value, and further prints the value on taking the nasdaq symbol as input. The link for the code is :