Dr. Mark Humphrys

School of Computing. Dublin City University.

Home      Blog      Teaching      Research      Contact

My big idea: Ancient Brain


CA114      CA170

CA668      CA669      Projects

Lab - stock prices


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)

ancientbrain.com      w2mind.org      humphrysfamilytree.com

On the Internet since 1987.

Wikipedia: Sometimes I link to Wikipedia. I have written something In defence of Wikipedia. It is often a useful starting point but you cannot trust it. Linking to it is like linking to a Google search. A starting point, not a destination. I automatically highlight in red all links to Wikipedia and Google search and other possibly-unreliable user-generated content.