Last Day of the Month

Posted on
Sat Jan 15, 2022 12:22 am
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Last Day of the Month

I need to have a schedule happen on the last day of the month... but am guessing this isn't possible thru the Schedule GUI, right ? In Date/Days Of The Month, I did try entering 31, 30, 29, 28 in hopes that whatever date it ran across first would make this work, but once I enter those numbers, they are automatically put back in sequence from low to high.

Posted on
Sat Jan 15, 2022 7:38 am
jalves offline
Posts: 744
Joined: Jun 16, 2013

Re: Last Day of the Month

How about if you have it run at 1201 am on the first day of every month but randomized to -10 minutes?

Running Indigo 2023.2 on a 24" iMac M1), OS X 14.4
Jeff

Posted on
Sat Jan 15, 2022 7:44 am
DaveL17 offline
User avatar
Posts: 6743
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Last Day of the Month

As far as I know, there's no direct way to do it with the Indigo UI. But I think it can probably be done simply with a conditional script.

Run your schedule every day.

On the condition tab, use this Python script (in the block that says, "If Python script returns True:"):
Code: Select all
import datetime as dt
try:
    now = dt.datetime.now()
    last_dom = dt.datetime(now.year, now.month, now.day + 1)
    return False
except:
    return True

In a nutshell, this script attempts to add one day to the current date. If the current day is the last day of the month, the script will generate an error (for example, trying to create a date of 2022-01-32). If the script generates an error, it will return the value of 'True', indicating that today is the last day of the month. This will allow the schedule to run.

At least that's the idea. :D

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Jan 15, 2022 8:07 am
CliveS offline
Posts: 761
Joined: Jan 10, 2016
Location: Medomsley, County Durham, UK

Re: Last Day of the Month

You could try setting a schedule for Day of month = 28,29,30,31 and Time at 00.01
Paste into Condition 'If Python script returns True'

Code: Select all

import calendar
from time import gmtime, strftime
lastDay = calendar.monthrange(int(strftime("%Y", gmtime())), int(strftime("%m", gmtime())))[1]
todayDay = int(strftime("%d"))
indigo.server.log(str(lastDay))    # Only required for testing
indigo.server.log(str(todayDay)) # Only required for testing
if str(todayDay) == str(lastDay):
# if str(todayDay) == str(todayDay):  #For testing - always return True
   return True
else:
   return False


CliveS

Indigo 2023.2.0 : macOS Ventura 13.6.3 : Mac Mini M2 : 8‑core CPU and 10‑core GPU : 8 GB : 256GB SSD
----------------------------------------------------------------------------------
The best way to get the right answer on the Internet is not to ask a question, it's to post the wrong answer

Posted on
Sat Jan 15, 2022 8:53 am
jltnol offline
Posts: 989
Joined: Oct 15, 2013

Re: Last Day of the Month

thanks

I'll give both of these options a try.

My problem with the 12:01 on the 1st with random is that the data in the file will all be from the previous month, but would be labeled with the current month at least sometimes. This was going to be my fall back compromise. At least Indigo would create a new file every month without my intervention, and naming the files correctly could have been easily done manually.

And I now realize that my idea of reversing the dates in the GUI wouldn't have worked either.

Posted on
Sun Jan 16, 2022 3:14 pm
ryanbuckner online
Posts: 1075
Joined: Oct 08, 2011
Location: Northern Virginia

Re: Last Day of the Month

Set your condition on a schedule run every day to fire if Python returns true. Check to see if tomorrow is in a different Month than today:

Code: Select all
import datetime

current_date = datetime.datetime.today()
nextday_date = datetime.datetime.today() + datetime.timedelta(days=1)
if (current_date.month != nextday_date.month):
    return True
else:
    return False


Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests