To create a code to print "Hi, <username>" when greet command is given and to print the current stock value when stock command is given.
from cmd2 import Cmd
from getpass import getuser
import requests
import sys
__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_sayit(self,line):
print "Python Rocks!"
def do_greet(self,line):
print "hi,%s" % (getuser())
def do_stockgoog(self,line):
a = requests.get("http://download.finance.yahoo.com/d/quotes.csv?s=GOOG&f=l1")
value=a.text
print value
if __name__ == '__main__':
app = Application()
app.cmdloop()