Python Conversion

Posted on
Tue Jul 03, 2018 12:44 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Python Conversion

I have another type of AS that strings together variables and some text or in this case the degree symbol °.
Appreciate a sample of this one if possible.
Code: Select all
tell application "IndigoServer"
   set the value of variable "WUForecastAll" to (value of variable "WUForecast") & " " & (value of variable "WUHighTemp") & (ASCII character 188) & "/" & (value of variable "WULowTemp") & (ASCII character 188)
end tell


Making good progress on eliminating my AS. Hadn't realized how many I actually used over the last 9 years.

Thanks,

Carl

Posted on
Tue Jul 03, 2018 2:21 pm
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python Conversion

Try this. I've added lots of comments and separated out each step into it's own line to illustrate the individual steps. Consider it a learning script:

Code: Select all
# Get the high temp value from the Indigo variable (all variable values are returned as strings)
high_temp = indigo.variables[ID_OF_WUHighTemp].value

# Get the low temp value from the Indigo variable (all variable values are returned as strings)
low_temp = indigo.variables[ID_OF_WULowTemp].value

# Get the forecast value from the Indigo variable (all variable values are returned as strings)
forecast = indigo.variables[ID_OF_WUForecast].value

# Create the combined string - notice the embedded degree symbols, they work great
# The open/close bracket notation means that it's going to have a value substituted there
# so the first one will get forecast, the second one high_temp, and the last low_temp. The
# resulting string is something like:
#     Very hot and dry. 103°/75°
combined_forecast = u"{} {}°/{}°".format(forecast, high_temp, low_temp)

# Set the value of the WUForecastAll variable to the combined_forecast string
# just created.
indigo.variable.updateValue(ID_OF_WUForecastAll, value=combined_forecast)


In future scripts, feel free to delete the comment lines (starting with the # sign). Again, I highly recommend doing a Python tutorial, it won't take very long and you'll gain a ton of understanding from doing it.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Jul 03, 2018 6:49 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Python Conversion

Really appreciate all the help.
No doubt your notes will be as well.

Many thanks,

Carl

Posted on
Tue Jul 03, 2018 7:53 pm
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Python Conversion

jay (support) wrote:
Again, I highly recommend doing a Python tutorial, it won't take very long and you'll gain a ton of understanding from doing it.

Two in particular I recommend are:

Google Python Class
MIT Open Courseware

What's fun about the second one is that you can say that you studied Python at MIT. :D

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

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests