# Pull rate from 2 yrs ago, 1 yr ago, etc dates['twoYearsAgo'] = (lastDate - timedelta(days=730)).date() dates['oneYearAgo'] = (lastDate - timedelta(days=365)).date() dates['sixMonthsAgo'] = (lastDate - timedelta(days=182)).date() dates['threeMonthsAgo'] = (lastDate - timedelta(days=91)).date() dates['oneMonthAgo'] = (lastDate - timedelta(days=30)).date() dates['twoWeeksAgo'] = (lastDate - timedelta(days=14)).date() dates['oneWeekAgo'] = (lastDate - timedelta(days=7)).date() dates['yesterday'] = (lastDate - timedelta(days=1)).date() dates['today'] = lastDate.date() dates = verifyDates( csv, dates, 'DATE', 'DGS3MO' ) # If above dates (2 yrs ago, 1 yr ago) are weekends, fix to weekday values = { 'twoYearsAgo': getValueFromCSV(csv, dates['twoYearsAgo'].strftime('%Y-%m-%d'), 'DATE', 'DGS3MO'), 'oneYearAgo': getValueFromCSV(csv, dates['oneYearAgo'].strftime('%Y-%m-%d'), 'DATE', 'DGS3MO'), 'sixMonthsAgo': getValueFromCSV(csv, dates['sixMonthsAgo'].strftime('%Y-%m-%d'), 'DATE', 'DGS3MO'), 'threeMonthsAgo': getValueFromCSV(csv, dates['threeMonthsAgo'].strftime('%Y-%m-%d'), 'DATE', 'DGS3MO'), 'oneMonthAgo': getValueFromCSV(csv, dates['oneMonthAgo'].strftime('%Y-%m-%d'), 'DATE', 'DGS3MO'), 'twoWeeksAgo': getValueFromCSV(csv, dates['twoWeeksAgo'].strftime('%Y-%m-%d'), 'DATE', 'DGS3MO'),
lastDate = datetime.strptime(csv['DATE'].iloc[-1], '%Y-%m-%d') # If we have a new update: if lastAvailableDate < lastDate: # Pull rate from 2 yrs ago, 1 yr ago, etc dates['twoYearsAgo'] = (lastDate - relativedelta(months=24)).date() dates['oneYearAgo'] = (lastDate - relativedelta(months=12)).date() dates['sixMonthsAgo'] = (lastDate - relativedelta(months=6)).date() dates['threeMonthsAgo'] = (lastDate - relativedelta(months=3)).date() dates['oneMonthAgo'] = (lastDate - relativedelta(months=1)).date() dates['today'] = lastDate.date( ) # update today to the date of the last unemployment data point (ex: 02/01/2021) # NO verifyDates needed, as all dates are "monthly day = 1" (Ex: Jan 1, Feb 1) values = { 'twoYearsAgo': getValueFromCSV(csv, dates['twoYearsAgo'].strftime('%Y-%m-%d'), 'DATE', 'UNRATE'), 'oneYearAgo': getValueFromCSV(csv, dates['oneYearAgo'].strftime('%Y-%m-%d'), 'DATE', 'UNRATE'), 'sixMonthsAgo': getValueFromCSV(csv, dates['sixMonthsAgo'].strftime('%Y-%m-%d'), 'DATE', 'UNRATE'), 'threeMonthsAgo': getValueFromCSV(csv, dates['threeMonthsAgo'].strftime('%Y-%m-%d'), 'DATE', 'UNRATE'), 'oneMonthAgo': getValueFromCSV(csv, dates['oneMonthAgo'].strftime('%Y-%m-%d'), 'DATE', 'UNRATE'), #'twoWeeksAgo': getValueFromCSV(csv,dates['twoWeeksAgo'].strftime('%Y-%m-%d'),'DATE','UNRATE'), #'oneWeekAgo': getValueFromCSV(csv,dates['oneWeekAgo'].strftime('%Y-%m-%d'),'DATE','UNRATE'), #'yesterday': getValueFromCSV(csv,dates['yesterday'].strftime('%Y-%m-%d'),'DATE','UNRATE'),