Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions get-yahoo-quotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

"""
get-yahoo-quotes.py: Script to download Yahoo historical quotes using the new cookie authenticated site.

Usage: get-yahoo-quotes SYMBOL

History

06-03-2017 : Created script

"""

__author__ = "Brad Luicas"
Expand All @@ -25,6 +21,7 @@
import time
import datetime
import requests
import calendar


def split_crumb_store(v):
Expand Down Expand Up @@ -75,22 +72,37 @@ def get_now_epoch():
# @see https://www.linuxquestions.org/questions/programming-9/python-datetime-to-epoch-4175520007/#post5244109
return int(time.time())


def get_time_epoch(iso_time):
return calendar.timegm(time.strptime(iso_time, '%Y-%m-%d'))

def download_quotes(symbol):
start_date = 0
end_date = get_now_epoch()

def download_quotes(symbol, start_date, end_date):
cookie, crumb = get_cookie_crumb(symbol)
get_data(symbol, start_date, end_date, cookie, crumb)


if __name__ == '__main__':
def main():
# If we have at least one parameter go ahead and loop overa all the parameters assuming they are symbols
start_date = get_time_epoch('1970-01-01')
end_date = get_now_epoch()

if len(sys.argv) == 1:
print("\nUsage: get-yahoo-quotes.py SYMBOL\n\n")
else:
for i in range(1, len(sys.argv)):
symbol = sys.argv[i]
print("--------------------------------------------------")
print("Downloading %s to %s.csv" % (symbol, symbol))
download_quotes(symbol)
print("--------------------------------------------------")
print("\nUsage: get-yahoo-quotes.py SYMBOL [optional yyyy-mm-dd]START_DATE [optional yyyy-mm-dd]END_DATE\n\n")
return

symbol = sys.argv[1]
if len(sys.argv) > 2:
start_date = get_time_epoch(sys.argv[2])

if len(sys.argv) > 3:
end_date = get_time_epoch(sys.argv[3])

print("Downloading %s to %s.csv" % (symbol, symbol))
download_quotes(symbol, start_date, end_date)


if __name__ == '__main__':
main()

print("--------------------------------------------------")