Kyle Pierce
10/02/2020, 6:46 PMTypeError: 'FunctionTask' object is not iterable
I dont know if im over complicating this.with Flow("Load Daily Tables", schedule) as flow:
start_date = Parameter('start_date', default='')
end_date = Parameter('end_date', default='')
dates = daterange(start_date, end_date)
# dates = ['2020-09-29', '2020-09-30']
@task(log_stdout=True)
def daterange(start_date, end_date):
print(start_date, end_date)
list_of_dates = []
# Keep the parameters short you can leave end_date blank and it will default to today.
if end_date == '':
eastern = timezone('US/Eastern')
single_date = datetime.now(eastern)
end_date = single_date
# If start_date is blank we are just going to pull yesterday
if start_date == '':
eastern = timezone('US/Eastern')
start_date = datetime.now(eastern)
elif start_date != '':
start_date = datetime.strptime(start_date, '%Y-%m-%d')
# Make start_date eastern
start_date = start_date.replace(tzinfo=eastern)
# Otherwise we are going to get a list of dates.
for n in range(int((end_date - start_date).days)):
single_date = (end_date - timedelta(n)).strftime("%Y-%m-%d")
list_of_dates.append(single_date)
print(list_of_dates)
return list_of_dates
Dylan
from prefect import task, Flow, Parameter
@task(log_stdout=True)
def daterange(start_date, end_date):
print(start_date, end_date)
list_of_dates = []
# Keep the parameters short you can leave end_date blank and it will default to today.
if end_date == "":
eastern = timezone("US/Eastern")
single_date = datetime.now(eastern)
end_date = single_date
# If start_date is blank we are just going to pull yesterday
if start_date == "":
eastern = timezone("US/Eastern")
start_date = datetime.now(eastern)
elif start_date != "":
start_date = datetime.strptime(start_date, "%Y-%m-%d")
# Make start_date eastern
start_date = start_date.replace(tzinfo=eastern)
# Otherwise we are going to get a list of dates.
for n in range(int((end_date - start_date).days)):
single_date = (end_date - timedelta(n)).strftime("%Y-%m-%d")
list_of_dates.append(single_date)
print(list_of_dates)
return list_of_dates
with Flow("Load Daily Tables") as flow:
start_date = Parameter("start_date", default="")
end_date = Parameter("end_date", default="")
dates = daterange(start_date, end_date)
# dates = ['2020-09-29', '2020-09-30']
schedule
)Kyle Pierce
10/02/2020, 7:05 PMwith Flow("Load Daily Tables") as flow:
start_date = Parameter("start_date", default="")
end_date = Parameter("end_date", default="")
dates = daterange(start_date, end_date)
# dates = ['2020-09-29', '2020-09-30']
table_list = ['flows', 'sms_replies']
# Two lists. dates and tables
# [date1, table1], [date1, table2], [date2, table1], [date2, table2]
combos = list(product(table_list, dates))
Dylan
product
?list
, that likely won’t evaluate properly(prefect) dylanhughes@Dylans-MacBook-Pro-Prefect ~/Desktop> ipython -i test.py
Python 3.7.7 (default, Mar 26 2020, 10:32:53)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help.
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
~/Desktop/test.py in <module>
35 # Two lists. dates and tables
36 # [date1, table1], [date1, table2], [date2, table1], [date2, table2]
---> 37 combos = list(product(table_list, dates))
NameError: name 'product' is not defined
Kyle Pierce
10/02/2020, 7:20 PMDylan
Kyle Pierce
10/02/2020, 7:34 PM