Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

Search:

CA216      CA249      CA318

CA400      CA651      CA668


Lab - stock prices


Assignment

Write a program to go on the Internet and get the price of a stock.
Usage like:
getprice (stock symbol)
For example:


For 40%

  1. We will get stock quotes from Yahoo, from pages like these:

  2. Stock price is contained in sections like this:
    • <span class="Fw(b) Fz(36px) Mb(-4px)" data-reactid="282">803.64</span>
    • <span class="Fw(b) Fz(36px) Mb(-4px)" data-reactid="269">62.28</span>
  3. Let us assume it is the only thing marked by Fz(36px) (Note how our script may fail in the future.)

  4. The first line of your script constructs the URL needed, given the command-line argument.
  5. When putting a variable in a string, note the two types of strings (single quotes and double quotes).
  6. Use wget to download the URL to a file.
  7. Test that is working, and the stock price is found somewhere in the file.

  8. When the above is working: Use grep to search the file for the relevant line.
  9. Test that you can extract the single line with the stock price on it.


For 60%

  1. When the above is working: Use sed to remove from start-of-line to the string Fz(36px) inside the <span ...>
  2. See string matching / regular expressions.
    See start of line, end of line.
    ".*" matches any sequence of characters.
  3. Check that this works before proceeding.


For 100%

  1. When the above is working: Use sed to remove from </span> to end of line.
  2. When the above is working: Use sed to remove from start-of-line to end of the <span ...>
  3. Your program should now just print the price.





Discussion and Notes (not needed for assignment)



Feeds      w2mind.org

On Internet since 1987.