An easy one: Day of the Week to Variable

Posted on
Sun Oct 20, 2019 7:42 am
chobo offline
Posts: 126
Joined: Dec 08, 2013
Location: USA

An easy one: Day of the Week to Variable

Hi all,

Just upgraded to 7.4 and have had pretty good success converting some other scripts. This one not so much...

Code: Select all
tell application "IndigoServer"
set today to current date
set weekdaytoday to the weekday of today
set value of variable "Day_of_week" to weekdaytoday
end tell

Thoughts?

Posted on
Sun Oct 20, 2019 8:26 am
Grognard offline
User avatar
Posts: 53
Joined: May 17, 2011
Location: Seabrook, TX

Re: An easy one: Day of the Week to Variable

This should work:

Code: Select all
from datetime import datetime, time
day_of_week = datetime.today().strftime("%A")

Posted on
Sun Oct 20, 2019 8:32 am
forestfield offline
Posts: 83
Joined: Dec 29, 2014
Location: West Sussex

Re: An easy one: Day of the Week to Variable

This should do it...

Code: Select all
import datetime

# create a list of days
days = [u'Monday', u'Tuesday', u'Wednesday', u'Thursday', u'Friday', u'Saturday', u'Sunday']
# choose today from that list
today = days[datetime.datetime.today().weekday()]

# create the indigo variable 'Day_of_Week', don't panic if to already exists
try:
  indigo.variable.create('Day_of_Week', value='')
except NameNotUniqueError:
  pass

# set 'Day_of_Week' to today
indigo.variable.updateValue(indigo.variables['Day_of_Week'].id, value=today)

Posted on
Sun Oct 20, 2019 8:35 am
forestfield offline
Posts: 83
Joined: Dec 29, 2014
Location: West Sussex

Re: An easy one: Day of the Week to Variable

Beaten to it,
and I forgot about strftime('%A') - may reuse that elsewhere

Posted on
Sun Oct 20, 2019 4:03 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: An easy one: Day of the Week to Variable

Just an FYI, you can also use the Python format specifier to turn datetime objects into formatted strings.

Code: Select all
now = indigo.server.getTime()
indigo.variable.updateValue("Day_of_week", u"{0:%A}".format(now))

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

[My Plugins] - [My Forums]

Posted on
Sun Oct 20, 2019 5:39 pm
chobo offline
Posts: 126
Joined: Dec 08, 2013
Location: USA

Re: An easy one: Day of the Week to Variable

Thanks, Grognard, forestfield, & DaveL17! This one is resolved!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest