Bidisha2git myshellv1 20130719-042036


Posted:

Objective:

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.

code:

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()

Contents © 2013 dgplug - Powered by Nikola
Share
UA-42392315-1