Setting a variable for Weekend

Posted on
Sat Dec 13, 2014 4:51 pm
miketeel offline
Posts: 11
Joined: Jun 26, 2013

Setting a variable for Weekend

I'd like to run a script only on weekend. Is there easy way to set and maintain a boolean variable that would be true on weekends?

Posted on
Sat Dec 13, 2014 5:30 pm
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Setting a variable for Weekend

miketeel wrote:
I'd like to run a script only on weekend. Is there easy way to set and maintain a boolean variable that would be true on weekends?

Here's a copy of the code that I use. There's more here than you need, but what you want is in there.

Code: Select all
from datetime import datetime, time

# ==== Globals ====
day_of_week = datetime.today().weekday()
time_of_day = datetime.now().time()
month = datetime.today().strftime("%B")
day = datetime.today().strftime("%A")
dayOfMonth = datetime.today().strftime("%d")
year = datetime.today().strftime("%Y")
fancyDate = "%s %s, %s" % (month, dayOfMonth, year)
fancyTime = "%s" % datetime.now().time().strftime("%I:%M")

indigo.variable.updateValue(171889768, day)
indigo.variable.updateValue(120808817, month)
indigo.variable.updateValue(692601213, dayOfMonth)
indigo.variable.updateValue(1376792491, year)
indigo.variable.updateValue(1356967768, fancyDate)
indigo.variable.updateValue(1150196462, fancyTime)

# ==== Weekday or Weekend? ====
if 0 <= day_of_week <= 4:
   weekday = u'Weekday'
else:
   weekday = u'Weekend'
indigo.variable.updateValue(1663542915, weekday)

# ==== AM or PM? ====
if time(00,00) <= time_of_day <= time(11,59):       
   am_pm = u'AM'
else:
   am_pm = u'PM'
indigo.variable.updateValue(949417705, am_pm)
Dave

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

[My Plugins] - [My Forums]

Posted on
Sat Dec 13, 2014 6:45 pm
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Setting a variable for Weekend

What causes the script to run exactly? Is it a trigger or schedule? The solution might be less complex than Dave's reply but I don't know until I get some context.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sat Dec 13, 2014 6:53 pm
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Setting a variable for Weekend

Here's the simpler version.

Code: Select all
from datetime import datetime, time

if 0 <= datetime.today().weekday() <= 4:
   weekday = u'False'
else:
   weekday = u'True'
indigo.variable.updateValue(VARIABLE ID, weekday)

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

[My Plugins] - [My Forums]

Posted on
Sat Dec 13, 2014 11:26 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Setting a variable for Weekend

I may be missing something here... But why not just schedule an action for some time Friday night or Saturday AM with an action to set your "weekend" variable true, and another scheduled action for Sunday night/ monday AM to set it false again.

Posted on
Sun Dec 14, 2014 12:04 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Setting a variable for Weekend

There might be several different and easier approaches - depending on the exact nature of the problem being solved... :wink:

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Sun Dec 14, 2014 5:44 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Setting a variable for Weekend

I use my dateTime script to update variable values for several different things. The most important is HVAC logic which accounts for weekday/weekend, AM/PM, home/away, holidays, and vacations. I also create some formatted strings for control pages.

Dave

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

[My Plugins] - [My Forums]

Posted on
Sun Dec 14, 2014 9:53 am
roussell offline
User avatar
Posts: 1108
Joined: Aug 18, 2008
Location: Alabama

Re: Setting a variable for Weekend

Here's a snippet from a larger time/day applescript that I have that runs at midnight every night:

Code: Select all
set weekend to {Saturday, Sunday}
if weekday of (current date) is in weekend then
   set value of variable "Weekend" to "Yes"
else
   set value of variable "Weekend" to "No"
end if

Posted on
Sun Dec 14, 2014 10:38 pm
miketeel offline
Posts: 11
Joined: Jun 26, 2013

Re: Setting a variable for Weekend

Thanks, Russell, your short script worked like a charm.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest