Web App to Get Stock Market Data from AlphaVantage Service

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Python please

starter code:

# Web App to Get Stock Market Data from AlphaVantage Service
import requests
#Function that gets stock info from API
# Returns results in list of two strings
# DO NOT EDIT THIS FUNCTION EXCEPT TO INSERT YOUR API KEY WHERE INDICATED
def getStock(symbol):
baseURL = "https://www.alphavantage.co/query?
function=GLOBAL_QUOTE&datatype=csv"
keyPart = "&apikey=" + "REPLACE WITH YOUR API KEY" #Add API key
symbolPart = "&symbol=" + symbol
stockResponse = requests.get(baseURL+keyPart+symbolPart)
return stockResponse.text #Return only text part of response
#Function that computes and displays results
def main():
# Add code that meets the program specifications (see instructions in Canvas)
#Code that starts the app
main()

main() function
The starter code includes a main() function that is called when the app starts. Add code to
make it:
1. Start by displaying this message: "Check stock prices."
2. Ask the user for a stock symbol.
3. Call getStock() with the stock symbol, and save the returned stock-price data.
4. Split the data (two text lines) into a list of two strings (hint: use string method .split(/).
5. If the split data is a list of two strings (each in CSV format), the data is good and the
stock was found. (Hint: if the stock symbol was valid. the length of the split data should
be 2.) Extract the stock's previous closing price, opening price, high price, low price,
Prof Jeff johnson
CS 110
and current price. Do it in a way that will still work if AlphaVantage changes the order
of items in the returned data. E.g. don't assume that the stock's opening price is in the
second position (index 1) in the list, because if your program assumes that and
tomorrow AlphaVantage moves the opening price to another position, your app won't
work anymore. Write your app so it finds each price no matter how they are ordered,
and uses the appropriate index to get each price.
6. Print the previous closing price, opening price, high price, current price, and low price.
7. If the split data is not a list of exactly 2 items (CSV strings), that means the stock symbol
was not found. In that case, tell the user the stock symbol was not found, and then
continue with step 10 (below).
8. When the app displays prices for a stock (but not when it can't find a stock), it should
also write the same information to an output file stock_prices.txt. Each time the app
successfully displays the prices for a stock, the app should append the information to
the file. Eg., if the user requests prices for three stocks, when the application quits,
stock_prices.txt should contain info for those three stocks, with a line like this separating
them: ====
====
9. The app should not clear and replace the data in stock_prices.txt each time it is run. It
should keep appending stock prices to the file.
10. The program should ask the user "Check another stock price? (Y or N)", and should
perform input validation to make users enter a valid response. If the response is "Y" or
"y", the program should loop back to Step 2 (not Step 1) and ask for another stock
symbol. If the response is “N" or "n", the program closes the output file and quits.
Transcribed Image Text:main() function The starter code includes a main() function that is called when the app starts. Add code to make it: 1. Start by displaying this message: "Check stock prices." 2. Ask the user for a stock symbol. 3. Call getStock() with the stock symbol, and save the returned stock-price data. 4. Split the data (two text lines) into a list of two strings (hint: use string method .split(/). 5. If the split data is a list of two strings (each in CSV format), the data is good and the stock was found. (Hint: if the stock symbol was valid. the length of the split data should be 2.) Extract the stock's previous closing price, opening price, high price, low price, Prof Jeff johnson CS 110 and current price. Do it in a way that will still work if AlphaVantage changes the order of items in the returned data. E.g. don't assume that the stock's opening price is in the second position (index 1) in the list, because if your program assumes that and tomorrow AlphaVantage moves the opening price to another position, your app won't work anymore. Write your app so it finds each price no matter how they are ordered, and uses the appropriate index to get each price. 6. Print the previous closing price, opening price, high price, current price, and low price. 7. If the split data is not a list of exactly 2 items (CSV strings), that means the stock symbol was not found. In that case, tell the user the stock symbol was not found, and then continue with step 10 (below). 8. When the app displays prices for a stock (but not when it can't find a stock), it should also write the same information to an output file stock_prices.txt. Each time the app successfully displays the prices for a stock, the app should append the information to the file. Eg., if the user requests prices for three stocks, when the application quits, stock_prices.txt should contain info for those three stocks, with a line like this separating them: ==== ==== 9. The app should not clear and replace the data in stock_prices.txt each time it is run. It should keep appending stock prices to the file. 10. The program should ask the user "Check another stock price? (Y or N)", and should perform input validation to make users enter a valid response. If the response is "Y" or "y", the program should loop back to Step 2 (not Step 1) and ask for another stock symbol. If the response is “N" or "n", the program closes the output file and quits.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY