To write a command greet, which will say Hi! to user. Solution: Imported getpass module. It did the rest
To write a command stock [NASDAQ], which will show the current share price of given NASDAQ symbol. Solution: Imported sharevalue module, which was our previous assignment. So just used it. I am too lazy to write same code again. Well we have to use the requests liabrary. So modified the code of sharevalue. Modified code is also given here.
1 #!/usr/bin/env python 2 3 importrequests 4 importsys 5 6 defshare(nasdaq): 7 8 """
9 Here all work is being done.
10 11 :arg nasdaq: NASDAQ symbol
12 """13 14 #Making the link in 'link' string to fetch data15 link='http://download.finance.yahoo.com/d/quotes.csv?s='+nasdaq+'&f=l1'16 print'Fetching recent share value of '+nasdaq17 18 share_value=requests.get(link)19 20 print'\n'+'Current share price of company '+nasdaq+': '+share_value.text21 share_value.close()22 23 24 if__name__=='__main__':25 26 #Counting the NASDAQ Symbol (Arguments)27 count=len(sys.argv)-128 29 #Checking if atleast one symbol available or not30 ifcount>=1:31 32 #NASDAQ symbol available passing it to main() function33 i=034 whilei<count:35 i+=136 share(sys.argv[i])