supriyasaha sharevalue2 20130712-143231    Posted:


CODE TO THE PROGRAM

the program is based on printing the current shrevalue of the nsdaq
  #!/usr/bin/env python

  import urllib2

  import sys

  def get_value(nasdaq): #to get the share value of nasdaq

   this function will get the share value of nasdaq

       url='http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=l1' % (nasdaq) #this the url of the nasdaq syambol extracted from yahho.finance

       con=urllib2.urlopen(url) #to open the url

       val=con.read() #to read the current share value of nasdaq symbol from yahoo.finanace


       print "the current sharevalue is %s" % (val)

   if __name__ == '__main__': #it calls the function to get the current sharevalu

   if len(sys.argv) == 2: #condition to check whter the file name in the command line does not exceed two

 it will check for the number of arguments in command line with ./shareval.py

     get_value(sys.argv[1]) #passe the nasdaq to the main user

else:

     print "Give only one NASDAQ symbol at a time after command line argument!"

sys.exit(0)

The explanation o the code

Here we use import urllib2 to get the current share value of symbol NASDAQ by using a function get_val.Now we open the url lin and read it to get the current sharevalue and print it. '_main_' is used to check weather in the command line input only one input symbol is given or more than one.If it exceed two includin the ./shareval.py then it will exit else it will print the current sharevalue of the symbol

the link to the code is https://github.com/supriyasaha/hometaskrepo/blob/master/sharevalue/shareval.py

Comments

elitalobo Mount v2 20130712-142304    Posted:


Mount v2

Task Write a file mount.py which when executed as ./mount.py gives the same output as mount command. For this we require to read /proc/mounts.

Code Description

readfile Function

  1. s=open("/proc/mounts") opens the file mount.py
  2. f=s.read() reads the content of the file /proc/mounts
  3. z=f.split("n") splits the output into individual lines
  4. changefile(z) calls the changefile function
  5. s.close() close /proc/mount file

changefile Function

  1. p=len(z) counts no of lines
  2. a=z[i].split(" ") splits each line into list of words
  3. a.insert(1,"on") inserts "on" in 1st position
  4. a.insert(3,"type") inserts "type" in 3rd position
  5. a.insert(5,"(") inserts open brackett in 5th position
  6. del a[-2] deletes the second last word
  7. del a[-1] deletes the last word
  8. a.append(")") appends a closed bracket at the end of the list
  9. w=" ".join(a) joins words in the list by " "
  10. print w prints each line

link to the code ` link <https://github.com/elitalobo/HomeTask1/tree/master/mount>`_

Comments

supriyasaha sharevalue 20130712-135835    Posted:


CODE TO THE PROGRAM

the program is based on rinting the current shrevalue of the nsdaq

#!/usr/bin/env python

import urllib2 import sys

def get_value(nasdaq): #to get the share value of nasdaq

this function will get the share value of nasdaq

url='http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=l1' % (nasdaq) #this the url of the nasdaq syambol extracted from yahho.finance con=urllib2.urlopen(url) #to open the url val=con.read() #to read the current share value of nasdaq symbol from yahho.finanace print "the cureent sharevalue is %s" % (val)

if __name__ == '__main__': #it recieves the desire coed and calls tha funtion to geth the current sharevalu

if len(sys.argv) == 2: #condition to check whter the file name in the command line does not exceed two

it will check for the number of arguments in command line with ./shareval.py

get_value(sys.argv[1]) #passe the nasdaq to the main user

else:

print "Give only one NASDAQ symbol at a time after command line argument!"

sys.exit(0)

The explanation o the code

Here we use import urllib2 to get the current share value of symbol NASDAQ by using a function get_val.Now we open the url lin and read it to get the current sharevalue and print it. '_main_' is used to check weather in the command line input only one input symbol is given or more than one.If it exceed two includin the ./shareval.py then it will exit else it will print the current sharevalue of the symbol

the link to the code is https://github.com/supriyasaha/hometaskrepo/blob/master/sharevalue/shareval.py

Comments

Rahul91 Introduction 20130712-132915    Posted:


Hi, my name is Rahul Mishra, I am pursuing my B-TECH from NSEC(kolkata) with CSE stream, currently i am in final year.

This training is very useful and unique in the form it is conducted, looking forward to it. :)

Comments

PriyankaKotiyal sharevalue 20130712-131706    Posted:


sharevalue

Question:

To print the latest price of the company whose NASDAQ symbol will be given in the command line

Solution:

  1. Modules are imported using the command import.
  2. A function share is defined to get the latest share price of the company.
  3. The link of the site to get the price is stored in a variable named share_link.
  4. The site(stored in the variable share_link) returns the latest value of the company by using the command urllib2.urlopen(share_link) and it is stored in the variable share_value.
  5. The share value of the company is being read by the command share_value.read() and is stored in the variable s.
  6. The share value of the company is printed by the print command.
  7. Then checking is made whether only one input is given or not in the command line by the command if __name__=='__main__':
  8. The program returns an error if more than one input is used.

Code

Execution

We can run the program like :-

$ chmod +x sharevalue.py

$ python sharevalue.py <NASDAQ symbol>

Comments

puspita23 SHAREVALUE 20130712-123924    Posted:


SHAREVALUE

Write a program in python to print the latest share value of a company whose NASDAQ symbol would be given as command line argument.

CODE EXPLANATION

step 1: From the main function check whether the input provided is a valid input or not. step 2: If its a valid input, pass the symbol as an argument in the function, else it will display an error message and exit. step 3: This function will provide the quoted price of the share and will print it.

def price(sym): #function to get the quoted price of the NASDAQ symbol entered as command line argument.
quote= urllib2.urlopen('http://download.finance.yahoo.com/d/quotes.csv?s='+sym+'&f=l1') #quote is an instance variable which is storing the quoted price at that instance, of that NASDAQ symbol
#Here we print the quoted price of the NASDAQ symbol entered.
print "This is the latest quote for the given NASDAQ symbol is " print quote.read() #we use read() as it is an instance variable

#Here is the main function where the argument passed in the commandline is checked to see whether it is a valid input or not.

if __name__ == '__main__':
if len(sys.argv) < 2 or len(sys.argv) > 2:
print "Incorrect entry. Enter a NASDAQ symbol" sys.exit(1)

link to the code: https://github.com/puspita23/puspita_utility/commit/291123932a2db6aca2fad1dac2133cc21118cb0c

Comments

anisha-agrawal sharevalue 20130712-112610    Posted:


Sharevalue

In this problem we write a python script which prints the latest share value of a company when its NASDAQ symbol is specified as a command line parameter. For example, to print the share value of Google Inc. (NASDAQ symbol GOOG), we run the script like:

$ ./sharevalue.py GOOG

The script with explanation:

The script checks if the command entered is in the correct format. If true, then getvalue() function is called and the NASDAQ symbol is passed to it. The getvalue() function fetches the share value from the url using urlopen() function of module urllib2 and stores it in a file. It the passes the file to printvalue() function which prints the share value.

#!/usr/bin/env python
import sys
import urllib2

def getvalue(symbol):
    """
    This function gets the latest share value of the inputted NASDAQ symbol.
    :arg symbol: NASDAQ symbol of a company.
    """
    url = 'http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=l1' % symbol
    # url for getting share value
    value = urllib2.urlopen(url) # file containing share value
    printvalue(value) # file passed to printvalue() which prints its contents

def printvalue(val):
    """
    This function prints the latest share value of the inputted NASDAQ symbol
    :arg val: Share value of imputted NASDAQ symbol of a company.
    """
    print "Share value: %s" % val.read()

if __name__ == '__main__':
    if len(sys.argv) != 2: #checks if command line parameters are equal to 2 or not
        print "Wrong parameter"
        print "Enter the command in this format: ./sharevalue.py <a valid NASDAQ symbol>"
        sys.exit(1)
    getvalue(sys.argv[1])
    #NASDAQ symbol passed to getvalue() if entered command is in correct format

The script can be found here

Comments

anurag619 sharevalue 20130712-110332    Posted:


here i am python script which will show us the latest nasdaq value. we will be using urllib2 module to fetch the url.

sharevalue.py code link.

import urllib2    #imports module urllib2.
import sys      #imports module sys.

def nasdaq(value):      #creating a function nasdaq.

        find = urllib2.urlopen('http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=l1'%value)        #urlopen function of urllib2 fetches the url along with the argument.
        print "NASDAQ value of %s is %s " %(value.upper(), find.read())  #prints the nasdaq value.
        find.close()

def main():     #function main.

        if len (sys.argv)!= 2:  #checking the length of arguments(condition).
         print "enter the script and the NASDAQ sysmbol, like GOOG,FB,YHOO etc" #print the condition statement.
        else:
         nasdaq(sys.argv[1])    #nasdaq function called.
        sys.exit(0)


if __name__ == '__main__':      #standard condition to call the main function.
        main()

to run the code

$python sharevalue.py FB

Comments

rahulc93 sharevalue v2 20130712-104534    Posted:


In this problem we will take a NASDAQ code as input from the user and return the current share value for that company

Source Code

The code to the problem can be found here

Solution

Here is the solution to the the problem.

#!/usr/bin/env python

import urllib2
import sys

def get_value(nasdaq):
    """
    This function fetches the current share value according to the NASDAQ code given by the user and displays it.

    :arg nasdaq: NASDAQ code given by the user
    """

    link = 'http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=l1' % (nasdaq)  # store the recquired URL acording to the NASDAQ value in the 'link' variable
    link_open = urllib2.urlopen(link)  # opening the URL
    price =  float(link_open.read())  # store the value retrieved from the URL in the 'price' variable
    if price == 0.00:  # incorrect NASDAQ value given by user
        print 'The NADAQ code entered is wrong. '  # display an error message
    else:
        print 'The latest share value is %s' % (price)  # display the value obtained from the URL

def main(nasdaq):
    """
    This function recieves the NASDAQ code and calls the desired function to fetch the current share value.

    :arg nasdaq: NASDAQ code given by the user
    """

    get_value(sys.argv[1])  # calls the 'get_value' method, passing to it the first command line parameter as argument


if __name__ == '__main__':
    if len(sys.argv) != 2:  # incorrect syntax for executing the program from command line
        print 'Wrong syntax. '  # display error message
        sys.exit(-1)  # abnormal termination
    else:  #syntax is ok
        main(sys.argv[1])  # pass the NASDAQ code to main given by user
    sys.exit(0)  # successful termination

Run the program

To run this script, follow the steps.

  1. Change the file's permissions and make it executable:

    $ chmod +x sharevalue.py
    
  2. Execute the file:

    $ ./sharevalue.py
    

Alternatively, you can also do:

$ python sharevalue.py

Comments

rahulc93 sharevalue 20130712-104156    Posted:


In this problem we will take a NASDAQ code as input from the user and return the current share value for that company

Source Code

The code to the problem can be found here

Solution

Here is the solution to the the problem.

#!/usr/bin/env python

import urllib2
import sys

def get_value(nasdaq):
    """
    This function fetches the current share value according to the NASDAQ code given by the user and displays it.

    :arg nasdaq: NASDAQ code given by the user
    """

    link = 'http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=l1' % (nasdaq)  # store the recquired URL acording to the NASDAQ value in the 'link' variable
    link_open = urllib2.urlopen(link)  # opening the URL
    price =  float(link_open.read())  # store the value retrieved from the URL in the 'price' variable
    if price == 0.00:  # incorrect NASDAQ value given by user
        print 'The NADAQ code entered is wrong. '  # display an error message
    else:
        print 'The latest share value is %s' % (price)  # display the value obtained from the URL

def main(nasdaq):
    """
    This function recieves the NASDAQ code and calls the desired function to fetch the current share value.

    :arg nasdaq: NASDAQ code given by the user
    """

    get_value(sys.argv[1])  # calls the 'get_value' method, passing to it the first command line parameter as argument


if __name__ == '__main__':
    if len(sys.argv) != 2:  # incorrect syntax for executing the program from command line
        print 'Wrong syntax. '  # display error message
        sys.exit(-1)  # abnormal termination
    else:  #syntax is ok
        main(sys.argv[1])  # pass the NASDAQ code to main given by user
    sys.exit(0)  # successful termination

Run the program

To run this script, follow the steps.

  1. Change the file's permissions and make it executable:

    $ chmod +x sharevalue.py
    
  2. Execute the file:

    $ ./sharevalue.py
    

Alternatively, you can also do:

$ python mount.py

Comments

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