Converting AppleScript that reads data from remote URL

Posted on
Mon Jun 29, 2020 1:59 pm
FlyingDiver offline
User avatar
Posts: 4241
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Converting AppleScript that reads data from remote URL

Yeah, the strings in that HTML are wonky to parse. This works:

Code: Select all
import requests

# output from gmcmap.com looks like this:
# {"time": "2019-08-04 10:44:53", "CPM": "19", "ACPM": "18.22", "uSv": "0.12"}

result = requests.get("http://www.gmcmap.com/historyData-plain.asp?Param_ID=68108722812")
lines = result.text.split(',')
words = lines[1].split(":")
cpm_value = words[1].replace('"','').replace(' ','')
indigo.variable.updateValue(385534937, cpm_value)


That gets rid of all the double-quotes and the space that's in the string.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Jun 29, 2020 2:04 pm
gmusser offline
Posts: 278
Joined: Feb 12, 2005
Location: New Jersey

Re: Converting AppleScript that reads data from remote URL

Hooray, it works! And I learned a bit more about Python. Thanks again.

Who is online

Users browsing this forum: GlennNZ and 1 guest