I wrote three if statements. The first one I made it True so that I can test it. Isn't it supposed to stop at the first statement evaluated to true ? It is showing me that the first statement and the last else statement are true. I'm trying to just make the first if statement run as a test.
skipdays = {'Monday': '2019-08-19', 'Tuesday': {'2019-08-20', '2019-10-
30'}}
skipday_date = date.today() - timedelta(days=3)
skipday_date = skipday_date.strftime("%Y-%m-%d")
skipday_day = date.today() - timedelta(days=3)
skipday_day = skipday_day.strftime('%A')
# Get all Mondays in the year
def allmondays(year):
d = date(year, 1, 1) # January 1st
d += timedelta(days=7 - d.weekday()) # First Monday
while d.year == year:
yield d
d += timedelta(days=7)
# Get current year
current_year = int(date.today().strftime('%Y'))
# If today is Monday's cycle day then subtract 3 to get Friday's cycle day
for (skipday, skipdate),monday in zip(skipdays.items(),
allmondays(current_year)):
if skipday_day == skipday and skipday_date in skipdate:
today = date.today() - timedelta(days=4)
col = today.strftime('%b').lower()
current_cycle_day = df[df[col] == today.day].index.values[0]
print("Today is a skip day")
print(current_cycle_day)
elif date.today() == monday:
today = date.today() - timedelta(days=3)
col = today.strftime('%b').lower()
current_cycle_day = df[df[col] == today.day].index.values[0]
print("Today is a Monday")
# If not Monday then just subtract 1 to get yesterday's cycle day.
else:
today = date.today() - timedelta(days=1)
col = today.strftime('%b').lower()
current_cycle_day = df[df[col] == today.day].index.values[0]
print("Today is a regular day")
print(current_cycle_day)
current results:
Today is a regular day
16
Today is a skip day
13
expected results:
Today is a regular day
16
"Today is a skip day"and"Today is a regular day"are printing? You must be running it twice then.forclause, which does look a bit complicated at first glance.ifandelsewill never both run.