Comments (4)
YahooData.fetch("TSLA", start="2000-01-01", end="2021-12-31")
I tried in python 2.7 and return 'TypeError: unbound method fetch() must be called with YahooData instance as first argument (got unicode instance instead)'
Do you know what changes needed for Python 2.7? I am in an old image in a cloud system and is hard for me to upgrade to python 3. Thanks
Hi, you can try with this code:
import io
import pandas
from datetime import datetime
import requests
class YahooData:
def fetch(self, ticker, start, end):
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9'
}
url = "https://query1.finance.yahoo.com/v7/finance/download/" + str(ticker)
x = int(datetime.strptime(start, '%Y-%m-%d').strftime("%s"))
y = int(datetime.strptime(end, '%Y-%m-%d').strftime("%s"))
url += "?period1=" + str(x) + "&period2=" + str(y) + "&interval=1d&events=history&includeAdjustedClose=true"
r = requests.get(url, headers=headers)
pd = pandas.read_csv(io.StringIO(r.text), index_col=0, parse_dates=True)
return pd
df = YahooData()
dfs = df.fetch("TSLA", start="2000-01-01", end="2021-12-31")
print(dfs)
Hopefully it can be useful, thanks :)
from yahoodata.
YahooData.fetch("TSLA", start="2000-01-01", end="2021-12-31")
I tried in python 2.7 and return 'TypeError: unbound method fetch() must be called with YahooData instance as first argument (got unicode instance instead)'
Do you know what changes needed for Python 2.7? I am in an old image in a cloud system and is hard for me to upgrade to python 3. ThanksHi, you can try with this code:
import io import pandas from datetime import datetime import requests class YahooData: def fetch(self, ticker, start, end): headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9' } url = "https://query1.finance.yahoo.com/v7/finance/download/" + str(ticker) x = int(datetime.strptime(start, '%Y-%m-%d').strftime("%s")) y = int(datetime.strptime(end, '%Y-%m-%d').strftime("%s")) url += "?period1=" + str(x) + "&period2=" + str(y) + "&interval=1d&events=history&includeAdjustedClose=true" r = requests.get(url, headers=headers) pd = pandas.read_csv(io.StringIO(r.text), index_col=0, parse_dates=True) return pd df = YahooData() dfs = df.fetch("TSLA", start="2000-01-01", end="2021-12-31") print(dfs)
Hopefully it can be useful, thanks :)
Thanks @ericsnth . This error exists ```
x = int(datetime.strptime(start, '%Y-%m-%d').strftime("%s"))
AttributeError: 'module' object has no attribute 'strptime'
from yahoodata.
YahooData.fetch("TSLA", start="2000-01-01", end="2021-12-31")
I tried in python 2.7 and return 'TypeError: unbound method fetch() must be called with YahooData instance as first argument (got unicode instance instead)'
Do you know what changes needed for Python 2.7? I am in an old image in a cloud system and is hard for me to upgrade to python 3. ThanksHi, you can try with this code:
import io import pandas from datetime import datetime import requests class YahooData: def fetch(self, ticker, start, end): headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9' } url = "https://query1.finance.yahoo.com/v7/finance/download/" + str(ticker) x = int(datetime.strptime(start, '%Y-%m-%d').strftime("%s")) y = int(datetime.strptime(end, '%Y-%m-%d').strftime("%s")) url += "?period1=" + str(x) + "&period2=" + str(y) + "&interval=1d&events=history&includeAdjustedClose=true" r = requests.get(url, headers=headers) pd = pandas.read_csv(io.StringIO(r.text), index_col=0, parse_dates=True) return pd df = YahooData() dfs = df.fetch("TSLA", start="2000-01-01", end="2021-12-31") print(dfs)
Hopefully it can be useful, thanks :)
Thanks @ericsnth . This error exists ```
x = int(datetime.strptime(start, '%Y-%m-%d').strftime("%s")) AttributeError: 'module' object has no attribute 'strptime'
make sure you have imported the datetime module in the following way:
from datetime import datetime
If I had to guess, you did this:
import datetime
if you import the datetime module only with 'import datetime', you can change the code with:
x = int(datetime.datetime.strptime(date, "%Y-%m-%d").strftime("%s"))
from yahoodata.
It works now. Thanks @ericsnth
from yahoodata.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yahoodata.