Created
September 27, 2021 17:39
-
-
Save bkatiemills/2c93e3f6857f5bb09513eefdf43af33d to your computer and use it in GitHub Desktop.
loop over dates example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dateutil import rrule | |
from datetime import datetime | |
def get_selection_profiles_loop(start, end, shape, pres): | |
now = datetime.strptime(start, "%Y-%m-%d") | |
later = datetime.strptime(end, "%Y-%m-%d") | |
previous = start | |
profiles = [] | |
for dt in rrule.rrule(rrule.MONTHLY, dtstart=now, until=later): | |
timestep = dt.strftime("%Y-%m-%d") | |
if timestep != previous: | |
profiles += get_selection_profiles(previous, timestep, strShape, presRange) | |
previous = timestep | |
if previous != end: | |
profiles += get_selection_profiles(previous, end, strShape, presRange) | |
return profiles | |
startDate = '2020-04-01' | |
endDate = '2020-08-03' | |
profiles = get_selection_profiles_loop(startDate, endDate, strShape, presRange) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment