Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created on 06-03-2022 02:36 PM - edited 06-03-2022 02:46 PM
So I am trying to implement this script
from datetime import datetime, timedelta, date
flowfile = session.get()
current_date= datetime.today().date()
if flowfile != None:
src_table_name = flowfile.getAttribute('src_table_name')
date_filter = str(current_date.replace(day =11))
if src_table_name in ['Income_project_BP', 'Plan_final_scenario', 'Plan_primary_scenario', 'ProductionCalendar', 'Subcontracting_BP']:
flowfile = session.putAttribute(flowfile, 'date_filter', date_filter)
session.transfer(flowfile, REL_SUCCESS)
else:
session.transfer(flowfile, REL_FAILURE)
And I've tried a lot of different ways but when it comes to "replace" method I'm always getting this error. Same thing when I am trying to use "strftime" method
What should I do? I really need this method.
Thank you beforehand!
Created 06-03-2022 03:54 PM
Hi,
I think something is happening when nifi is trying to interpret the correct data type in python. to make it work make the current_date string as follows:
current_date= str(datetime.today().date())
and let the python engine do the conversion to the correct datetime type when you set the date_filter as follows:
date_filter = str(datetime.strptime(current_date,'%Y-%m-%d').replace(day =11))
Not sure if this is a bug in Nifi, but at least this should be a work around.
Hope that helps.
Created 06-03-2022 03:54 PM
Hi,
I think something is happening when nifi is trying to interpret the correct data type in python. to make it work make the current_date string as follows:
current_date= str(datetime.today().date())
and let the python engine do the conversion to the correct datetime type when you set the date_filter as follows:
date_filter = str(datetime.strptime(current_date,'%Y-%m-%d').replace(day =11))
Not sure if this is a bug in Nifi, but at least this should be a work around.
Hope that helps.
Created 06-03-2022 04:44 PM
Hello! Thank you so much it worked!
Can you please explain me how can I make date_filter with format %Y%m%d instead of %Y-%m-%d?
Created on 06-03-2022 05:11 PM - edited 06-03-2022 05:11 PM
set the date filter as follows:
date_filter = datetime.strptime(current_date,'%Y-%m-%d').replace(day =11).strftime('%Y%m%d')
If that solves your problem please accept solution.
Thanks
Created on 06-04-2022 12:22 AM - edited 06-04-2022 11:20 AM
thank you again. kind sir!!
I am trying to do this to increase a year, but ni-fi says there are no viable alternative at input '='
what am I doing wrong?
end_next_year = datetime.strptime(current_date,'%Y-%m-%d').replace(year = datetime.strptime(current_date,'%Y-%m-%d').year + 1).strftime('%Y1231')
Created 06-04-2022 07:54 AM
Try this:
end_next_year = datetime.strptime(current_date,'%Y-%m-%d').replace(year = datetime.strptime(current_date,'%Y-%m-%d').year+1).strftime('%Y%m%d')
Created 06-04-2022 11:38 AM
Hello! Still same error unfortunately 😞
Created 06-04-2022 01:08 PM
It worked for me. I have tried it before posting it and got the expected result. make sure the old code that was throwing the error is not there
Created 06-05-2022 08:27 AM
I've installed the last version of ni-fi and it solved all problems!
Thank you!