I've created a program that iterates through dates and sends data specific to those dates from an Excel spreadsheet to a web form.
I want to break out of all loops if one or both of the following conditions are met:
- The end of the month is reached;
- The iterated date reaches the current date
So far, breaking out of the loop works for the first condition but not the second.
I've tried checking the date in the excel document against the current date and breaking if the two are equal, but it doesn't work.
Any thoughts?
sg.theme('DARKTEAL')
layout = [[sg.Text('Date to Start Summing', font=('Arial', 10), visible=True),
sg.In(key='-CAL-', size=(12, None), default_text='MM/DD/YYYY')],
[sg.CalendarButton('Calendar', key='-OUTPUT-', target='-CAL-', pad=None, size=(10, None), font=('Arial', 10),
format='%m/%d/%Y')],
[sg.Text('Filename', key='-FOUTPUT-', font=('Arial', 10))],
[sg.In(visible=False),
sg.Input(key='-DIR-', size=(20, None)),
sg.FileBrowse('Browse', target='-DIR-', font=('Arial', 10))],
[sg.OK(font=('Arial', 10)), sg.Cancel(font=('Arial', 10))]]
window = sg.Window('Data Collector', layout, grab_anywhere=False, size=(400, 280), return_keyboard_events=True,
finalize=True)
event, values = window.read()
window['-OUTPUT-'](values['-CAL-'])
window['-FOUTPUT-'](values['-DIR-'])
acedate = (values['-CAL-'])
file = (values['-DIR-'])
window.close()
# length of bx measures
x = len(df.columns)
# used to determine when at end of row
z = 1
# location of column to start summing
b = 1
# number of days in the month
c = len(df.index)
# used to stop once last day of month reached
y = 1
# slices date chosen from calendar (dd) to determine where to start summing
n = int(values['-CAL-'][3:5])
# today's date (used to stop once current day is reached)
d = datetime.today().strftime('%Y-%m-%d')
while n < c:
while z < x:
m = df.iloc[n, b]
z = z + 1
b = b + 1
if pd.isnull(m):
tab()
continue
else:
ActionChains(browser) \
.send_keys(str(m)) \
.perform()
if z == x:
n = n + 1
y = y + 1
z = 1
b = 1
enter()
if n == c or str(pd.to_datetime(df.iloc[n, 0]).date()) == d:
break
time.sleep(5)
page_up()
time.sleep(5)
bx_select()
time.sleep(2)
clear()
time.sleep(5)
else:
tab()
time.sleep(0.5)