Skip to content

Commit

Permalink
made functions adhere to pep8 standards and threw deprecation warning…
Browse files Browse the repository at this point in the history
…s on old functions
  • Loading branch information
AndrewRPorter committed Nov 29, 2019
1 parent 5ad49da commit 6e0c91e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name="yahoo_historical",
packages=["yahoo_historical"],
version="0.3.1",
version="0.3.2",
description="Fetches historical EOD (end of day) prices from yahoo finance",
author="Andrew Porter",
author_email="[email protected]",
Expand Down
42 changes: 36 additions & 6 deletions yahoo_historical/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime as dt
import re
import time
import warnings

import pandas as pd
import requests
Expand Down Expand Up @@ -44,8 +45,7 @@ def init(self):
crumb = crumb.replace(u"\\u002F", "/")
return cookie, crumb # return a tuple of crumb and cookie

def getData(self, events):
"""Returns a list of historical data from Yahoo Finance"""
def _get(self, events):
if self.interval not in ["1d", "1wk", "1mo"]:
raise ValueError("Incorrect interval: valid intervals are 1d, 1wk, 1mo")

Expand All @@ -55,22 +55,52 @@ def getData(self, events):
content = StringIO(data.content.decode("utf-8"))
return pd.read_csv(content, sep=",")

def getHistorical(self, events="history"):
def getData(self, events):
"""Returns a list of historical data from Yahoo Finance"""
warnings.warn("getData has been deprecated, use get_data instead", DeprecationWarning)
return self._get(events)

def getHistorical(self):
"""Returns a list of historical price data from Yahoo Finance"""
return self.getData("history")
warnings.warn("getHistorical has been deprecated, use get_historical instead", DeprecationWarning)
return self._get("history")

def getDividends(self):
"""Returns a list of historical dividends data from Yahoo Finance"""
return self.getData("div")
warnings.warn("getDividends has been deprecated, use get_dividends instead", DeprecationWarning)
return self._get("div")

def getSplits(self):
"""Returns a list of historical splits data from Yahoo Finance"""
return self.getData("split")
warnings.warn("getSplits has been deprecated, use get_splits instead", DeprecationWarning)
return self._get("split")

def getDatePrice(self):
"""Returns a DataFrame for Date and Price from getHistorical()"""
warnings.warn("getDatePrice has been deprecated, use get_date_price instead", DeprecationWarning)
return self.getHistorical().iloc[:, [0, 4]]

def getDateVolume(self):
"""Returns a DataFrame for Date and Volume from getHistorical()"""
warnings.warn("getDateVolume has been deprecated, use get_date_volume instead", DeprecationWarning)
return self.getHistorical().iloc[:, [0, 6]]

def get_historical(self):
"""PEP8 friendly version of deprecated getHistorical function"""
return self._get("history")

def get_dividends(self):
"""PEP8 friendly version of deprecated getDividends function"""
return self._get("div")

def get_splits(self):
"""PEP8 friendly version of deprecated getSplits function"""
return self._get("split")

def get_date_price(self):
"""PEP8 friendly version of deprecated getDatePrice function"""
return self.get_historical().iloc[:, [0, 4]]

def get_date_volume(self):
"""PEP8 friendly version of deprecated getDateVolume function"""
return self.get_historical().iloc[:, [0, 6]]

0 comments on commit 6e0c91e

Please sign in to comment.