I am downloading data from an API, the maximum look back period is 833 days, but from my testing I know they have data going back to 2002. I have a function below that defines 833 days from today into the two date times "end" and "start", these are fed into an API command. Note they need to be in a string format and formatted in that way for the api to accept them.
d=datetime.today()
end = str(d.year) + "-" + str(d.month) + "-" + str(d.day)
lookbook_period = 833
# Take current date and minus the the max time delta of 833 days to get 'start' var
time_delta = timedelta(days=lookbook_period)
now = datetime.now()
#split the answer and format it to the required timestamp type.
start = str(now - time_delta).split(" ")[0]
What I want to do is download the dataframes in 833 day sections and then piece them all together into a CSV or dataframe. I have below what I have so far but I am not sure how to make a function that changes the dates as it goes.
def time_machine():
df_total = pd.DataFrame
start_str = str(2002) + "-0" + str(5) + "-0" + str(1)
start = datetime(2002,5,1)
print(start)
# amount of days from 2002-05-01 to now
rolling_td = timedelta(days=int(str((datetime.today() - start)).split(" ")[0]))
print(rolling_td, "\n")
# API maximum amount of lookbook days
max_td = timedelta(days=833)
# The function would do something similar to this, and on each pass, calling the API and saving the data to a dataframe or CSV.
s1 = start + max_td
print(s1)
s2 = s1 + max_td
print(s2)
s3 = s2 + max_td
print(s3)
d=datetime.today()
end = str(d.year) + "-" + str(d.month) + "-" + str(d.day)
print(d)
Any suggestions or tools/libraries to look at would be greatly appreciated. I have been testing things with while-loops but I am still running blindly into the dark on this one.
This a rough sudo code of what I think I need, but Im still unsure on how to move onto the next section
while count > 0 and > 833:
start =
end =
call the API first to download first set of data.
Check date range:
get most recent date + 833 days to it
Download next section
repeat
if count < 833:
calulate requied dates for start and end