Custom Trigger Monthly Open Days

Solved!
Sylvie
Level 2
Custom Trigger Monthly Open Days

Hello,

 

I'm trying to launch scenario with custom trigger the first open day of each month. Did someone could help me on that ? 

 

Thanks

0 Kudos
1 Solution
Sylvie
Level 2
Author

I finallly found the solution : 


from dataiku.scenario import Trigger
import pandas as pd
from datetime import date , datetime
import pytz


t = Trigger()

liste= pd.date_range('1/1/2023',periods=100, freq='BMS')


tz = pytz.timezone('Europe/Paris')


hour = datetime.now(tz = tz).hour


if date.today() in liste and hour>9 :
t.fire()

View solution in original post

4 Replies
imanousar
Level 3

You can use this library. You can see some examples here as well.

import dataikuapi
import dataiku
from dataiku.scenario import Trigger
import datetime


# 1st approach
client = dataiku.api_client()
project = client.get_project("your_project")

scenario = project.get_scenario("myscenario")
trigger_fire = scenario.run()

if today ==1:
    scenario_run = trigger_fire.wait_for_scenario_run()


# 2nd approach
t = Trigger()
today = datetime.datetime.today().day
if today == 1:
    t.fire()
Sylvie
Level 2
Author

Thanks for your help, but my problem is to run the scenario the first OPEN day of the month. So if the first is a sunday, the scenario should run the 2nd, monday. 

0 Kudos
MiguelangelC
Dataiker

Hi,

I suspect that by open day you actually mean business day?

If so you can take advantage of pandas date_range method. In your custom python trigger you could input.

from dataiku.scenario import Trigger
import pandas as pd
from datetime import date
t = Trigger()
if date.today() in pd.date_range('1/1/2023', '12/1/2023', freq='BMS')
  t.fire()

 

Sylvie
Level 2
Author

I finallly found the solution : 


from dataiku.scenario import Trigger
import pandas as pd
from datetime import date , datetime
import pytz


t = Trigger()

liste= pd.date_range('1/1/2023',periods=100, freq='BMS')


tz = pytz.timezone('Europe/Paris')


hour = datetime.now(tz = tz).hour


if date.today() in liste and hour>9 :
t.fire()