0

I'm following Sentdex' tutorials for mathplotlib, and i'm stuck at this video: #8 getting data from the internet: https://www.youtube.com/watch?v=IbUa1tTT-7k&t=625s

the provided code looks like this:

import matplotlib.pyplot as plt
import numpy as np
import urllib
import matplotlib.dates as mdates
def graph_data(stock):
stock_price_url = http://chartapi.finance.yahoo.com/instrument/1.0/'+stock+'/chartdata;type=quote;range=10y/csv'

source_code = urllib.request.urlopen(stock_price_url).read().decode()

stock_data = []
split_source = source_code.split('\n')

for line in split_source:
    split_line = line.split(',')
    if len(split_line) == 6:
        if 'values' not in line:
            stock_data.append(line)

Apparently the yahoo.api doesn't work anymore. I tried to find some different source, but if I use another url, I get an 'invalid character' error in any case.
I also tried urllib3 and couldn't/shouldn't I use the requests module? I don't care if it's finance, sports or weather data, but I'd be glad, if I could continue with this tutorial, or if you could point out a better alternative.

1 Answer 1

1

don't worry about doing the exact same thing as the instructor did. use alternatives. if not stock why not some data from unicef or who?

import matplotlib.pyplot as plt
import numpy as np
import urllib, json
import matplotlib.dates as mdates

url = 'https://data.cityofchicago.org/resource/f7f2-ggz5.json?fuel_type_code=LPG'
# from https://dev.socrata.com/consumers/getting-started.html
a = urllib.request.urlopen(url).read().decode()
print (a)

You have some data to play with now. you can find more from https://www.forbes.com/sites/bernardmarr/2016/02/12/big-data-35-brilliant-and-free-data-sources-for-2016/#24627925b54d

OR

you can just download the csv file of TSLA stock for 10 years here http://www.nasdaq.com/symbol/tsla/historical then import it as csv. instead of reading from the net, you will be reading from the file. It won't be same but it will be better than nothing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.