Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,807,597 Members 51,129 Now Online
XDA Developers Android and Mobile Development Forum

need help with variable split

Tip us?
 
cesar.maranhao
Old
(Last edited by cesar.maranhao; 24th August 2014 at 12:39 PM.)
#1  
Member - OP
Thanks Meter 3
Posts: 69
Join Date: Dec 2013
Default need help with variable split

i am doing an automated weather forecast with tasker and already have the api for wunderground.

i managed to make several splits until i reduced the entire text to this (and here is my problem):

var2
<![CDATA[HERE COMES THE TEXT I WANT TASKER TO READ OUT LOUD]]>

the problem is that i cannot break this the way i want it. if i do not give an argument in spliter, it divides like this:

var21
<![CDATA[HERE

var 22
COMES

var3
THE

var23
etc

when i set tasker to read, it reads everything and it goes like

"less than CDATA Here comes the..........greater than"

i really need to break that piece of information but if i set the splitter argument to <![CDATA[> it maintains it there and the variable after the split result is the same.

var21
<![CDATA[HERE COMES THE TEXT I WANT TASKER TO READ OUT LOUD]]>

which is exactly the same as var2

is almost like i cannot remove it. any tips?
 
Aerowinder
Old
#2  
Recognized Contributor
Thanks Meter 1,229
Posts: 3,104
Join Date: Aug 2012
Try Variable Section action.
 

Google Firmware: Google
USB Drivers: Google | Mirror
ADB+ADB Drivers: 19.0.2 (4.4.4) + Koush Universal ADB Drivers

TWRP Official: hammerhead | flo
TWRP Holofied: hammerhead | flo

Gapps: jajb

Superuser: Chainfire | Mirror
The Following User Says Thank You to Aerowinder For This Useful Post: [ Click to Expand ]
 
cesar.maranhao
Old
(Last edited by cesar.maranhao; 24th August 2014 at 04:06 PM.)
#3  
Member - OP
Thanks Meter 3
Posts: 69
Join Date: Dec 2013
Quote:
Originally Posted by Aerowinder View Post
Try Variable Section action.
i tried it, it solved part of the problem. thanks

now i only have to find a way to eliminate the > at the end

(this is because the text i get does not have a fixed number of characters)
 
Aerowinder
Old
#4  
Recognized Contributor
Thanks Meter 1,229
Posts: 3,104
Join Date: Aug 2012
Quote:
Originally Posted by cesar.maranhao View Post
i tried it, it solved part of the problem. thanks

now i only have to find a way to eliminate the > at the end

(this is because the text i get does not have a fixed number of characters)
Give me the entire string you are pulling from WU. I'll plug it in and do some tests.
 

Google Firmware: Google
USB Drivers: Google | Mirror
ADB+ADB Drivers: 19.0.2 (4.4.4) + Koush Universal ADB Drivers

TWRP Official: hammerhead | flo
TWRP Holofied: hammerhead | flo

Gapps: jajb

Superuser: Chainfire | Mirror
 
cesar.maranhao
Old
(Last edited by cesar.maranhao; 24th August 2014 at 09:53 PM.)
#5  
Member - OP
Thanks Meter 3
Posts: 69
Join Date: Dec 2013
Quote:
Originally Posted by Aerowinder View Post
Give me the entire string you are pulling from WU. I'll plug it in and do some tests.
there you go.. how do you think i can do this? i have put in bold a small segment i want to retrieve

Quote:
<response>
<version>0.1</version>
<termsofService>http://www.wunderground.com/weather/api/d/terms.html</termsofService>
<features>
<feature>forecast</feature>
</features>
<forecast>
<txt_forecast>
<date>8:18 PM WEST</date>
<forecastdays>
<forecastday>
<period>0</period>
<icon>clear</icon>
<icon_url>http://icons.wxug.com/i/c/k/clear.gif</icon_url>
<title>Sunday</title>
<fcttext><![CDATA[Mainly clear. Lows overnight in the mid 50s.]]></fcttext>
<fcttext_metric><![CDATA[Mainly clear. Low 13C.]]></fcttext_metric>
<pop>0</pop>
</forecastday>
<forecastday>
<period>1</period>
<icon>nt_clear</icon>
<icon_url>http://icons.wxug.com/i/c/k/nt_clear.gif</icon_url>
<title>Sunday Night</title>
<fcttext><![CDATA[Clear skies. Low 54F. Winds NNW at 5 to 10 mph.]]></fcttext>
<fcttext_metric><![CDATA[Clear skies. Low 13C. Winds light and variable.]]></fcttext_metric>
<pop>0</pop>
</forecastday>
<forecastday>
<period>2</period>
<icon>clear</icon>
<icon_url>http://icons.wxug.com/i/c/k/clear.gif</icon_url>
<title>Monday</title>
<fcttext><![CDATA[Sunny skies. High near 75F. Winds NW at 5 to 10 mph.]]></fcttext>
<fcttext_metric><![CDATA[Sunny skies. High around 25C. Winds NW at 10 to 15 km/h.]]></fcttext_metric>
<pop>0</pop>
</forecastday>
<forecastday>
<period>3</period>
<icon>nt_mostlycloudy</icon>
<icon_url>http://icons.wxug.com/i/c/k/nt_mostlycloudy.gif</icon_url>
<title>Monday Night</title>
<fcttext><![CDATA[Partly cloudy skies during the evening will give way to cloudy skies overnight. Low near 65F. Winds WNW at 5 to 10 mph.]]></fcttext>
<fcttext_metric><![CDATA[Partly cloudy during the evening followed by cloudy skies overnight. Low 18C. Winds WNW at 10 to 15 km/h.]]></fcttext_metric>
<pop>10</pop>
</forecastday>
<forecastday>
<period>4</period>
<icon>partlycloudy</icon>
<icon_url>http://icons.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<title>Tuesday</title>
<fcttext><![CDATA[Cloudy early with partial sunshine expected late. High 76F. Winds WSW at 5 to 10 mph.]]></fcttext>
<fcttext_metric><![CDATA[Cloudy skies early, followed by partial clearing. High near 25C. Winds WSW at 10 to 15 km/h.]]></fcttext_metric>
<pop>20</pop>
</forecastday>
<forecastday>
<period>5</period>
<icon>nt_partlycloudy</icon>
<icon_url>http://icons.wxug.com/i/c/k/nt_partlycloudy.gif</icon_url>
<title>Tuesday Night</title>
<fcttext><![CDATA[Partly to mostly cloudy. Low 66F. Winds light and variable.]]></fcttext>
<fcttext_metric><![CDATA[Partly to mostly cloudy. Low 18C. Winds light and variable.]]></fcttext_metric>
<pop>10</pop>
</forecastday>
<forecastday>
<period>6</period>
<icon>partlycloudy</icon>
<icon_url>http://icons.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<title>Wednesday</title>
<fcttext><![CDATA[Considerable clouds early. Some decrease in clouds later in the day. High 76F. Winds W at 5 to 10 mph.]]></fcttext>
<fcttext_metric><![CDATA[Partly to mostly cloudy. High near 25C. Winds W at 10 to 15 km/h.]]></fcttext_metric>
<pop>20</pop>
</forecastday>
<forecastday>
<period>7</period>
<icon>nt_chancerain</icon>
<icon_url>http://icons.wxug.com/i/c/k/nt_chancerain.gif</icon_url>
<title>Wednesday Night</title>
<fcttext><![CDATA[Rain showers early with overcast skies late. Low 64F. Winds NW at 5 to 10 mph. Chance of rain 40%.]]></fcttext>
<fcttext_metric><![CDATA[Showers in the evening, then cloudy overnight. Low 18C. Winds WNW at 10 to 15 km/h. Chance of rain 40%.]]></fcttext_metric>
<pop>40</pop>
</forecastday>
</forecastdays>
</txt_forecast>
<simpleforecast>
<forecastdays>
<forecastday>
<date>
<epoch>1408903200</epoch>
<pretty_short>7:00 PM WEST</pretty_short>
<pretty>7:00 PM WEST on August 24, 2014</pretty>
<day>24</day>
<month>8</month>
<year>2014</year>
<yday>235</yday>
<hour>19</hour>
<min>00</min>
<sec>0</sec>
<isdst>1</isdst>
<monthname>August</monthname>
<monthname_short>Aug</monthname_short>
<weekday_short>Sun</weekday_short>
<weekday>Sunday</weekday>
<ampm>PM</ampm>
<tz_short>WEST</tz_short>
<tz_long>Europe/Lisbon</tz_long>
</date>
<period>1</period>
<high>
<fahrenheit>69</fahrenheit>
<celsius>20</celsius>
</high>
<low>
<fahrenheit>54</fahrenheit>
<celsius>12</celsius>
</low>
<conditions>Clear</conditions>

<icon>clear</icon>
<icon_url>http://icons.wxug.com/i/c/k/clear.gif</icon_url>
<skyicon></skyicon>
<pop>0</pop>
<qpf_allday>
<in>0.00</in>
<mm>0</mm>
</qpf_allday>
<qpf_day>
<in></in>
<mm></mm>
</qpf_day>
<qpf_night>
<in>0.00</in>
<mm>0</mm>
</qpf_night>
<snow_allday>
<in>0.0</in>
<cm>0.0</cm>
</snow_allday>
<snow_day>
<in></in>
<cm></cm>
</snow_day>
<snow_night>
<in>0.0</in>
<cm>0.0</cm>
</snow_night>
<maxwind>
<mph>0</mph>
<kph>0</kph>
<dir></dir>
<degrees>0</degrees>
</maxwind>
<avewind>
<mph>0</mph>
<kph>0</kph>
<dir></dir>
<degrees>0</degrees>
</avewind>
<avehumidity>88</avehumidity>
<maxhumidity>0</maxhumidity>
<minhumidity>0</minhumidity>
</forecastday>

<forecastday>
<date>
<epoch>1408989600</epoch>
<pretty_short>7:00 PM WEST</pretty_short>
<pretty>7:00 PM WEST on August 25, 2014</pretty>
<day>25</day>
<month>8</month>
<year>2014</year>
<yday>236</yday>
<hour>19</hour>
<min>00</min>
<sec>0</sec>
<isdst>1</isdst>
<monthname>August</monthname>
<monthname_short>Aug</monthname_short>
<weekday_short>Mon</weekday_short>
<weekday>Monday</weekday>
<ampm>PM</ampm>
<tz_short>WEST</tz_short>
<tz_long>Europe/Lisbon</tz_long>
</date>
<period>2</period>
<high>
<fahrenheit>75</fahrenheit>
<celsius>24</celsius>
</high>
<low>
<fahrenheit>65</fahrenheit>
<celsius>18</celsius>
</low>
<conditions>Clear</conditions>

<icon>clear</icon>
<icon_url>http://icons.wxug.com/i/c/k/clear.gif</icon_url>
<skyicon></skyicon>
<pop>0</pop>
<qpf_allday>
<in>0.00</in>
<mm>0</mm>
</qpf_allday>
<qpf_day>
<in>0.00</in>
<mm>0</mm>
</qpf_day>
<qpf_night>
<in>0.00</in>
<mm>0</mm>
</qpf_night>
<snow_allday>
<in>0.0</in>
<cm>0.0</cm>
</snow_allday>
<snow_day>
<in>0.0</in>
<cm>0.0</cm>
</snow_day>
<snow_night>
<in>0.0</in>
<cm>0.0</cm>
</snow_night>
<maxwind>
<mph>10</mph>
<kph>16</kph>
<dir>NW</dir>
<degrees>313</degrees>
</maxwind>
<avewind>
<mph>9</mph>
<kph>14</kph>
<dir>NW</dir>
<degrees>313</degrees>
</avewind>
<avehumidity>67</avehumidity>
<maxhumidity>0</maxhumidity>
<minhumidity>0</minhumidity>
</forecastday>

<forecastday>
<date>
<epoch>1409076000</epoch>
<pretty_short>7:00 PM WEST</pretty_short>
<pretty>7:00 PM WEST on August 26, 2014</pretty>
<day>26</day>
<month>8</month>
<year>2014</year>
<yday>237</yday>
<hour>19</hour>
<min>00</min>
<sec>0</sec>
<isdst>1</isdst>
<monthname>August</monthname>
<monthname_short>Aug</monthname_short>
<weekday_short>Tue</weekday_short>
<weekday>Tuesday</weekday>
<ampm>PM</ampm>
<tz_short>WEST</tz_short>
<tz_long>Europe/Lisbon</tz_long>
</date>
<period>3</period>
<high>
<fahrenheit>76</fahrenheit>
<celsius>24</celsius>
</high>
<low>
<fahrenheit>66</fahrenheit>
<celsius>19</celsius>
</low>
<conditions>Partly Cloudy</conditions>

<icon>partlycloudy</icon>
<icon_url>http://icons.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<skyicon></skyicon>
<pop>20</pop>
<qpf_allday>
<in>0.00</in>
<mm>0</mm>
</qpf_allday>
<qpf_day>
<in>0.00</in>
<mm>0</mm>
</qpf_day>
<qpf_night>
<in>0.00</in>
<mm>0</mm>
</qpf_night>
<snow_allday>
<in>0.0</in>
<cm>0.0</cm>
</snow_allday>
<snow_day>
<in>0.0</in>
<cm>0.0</cm>
</snow_day>
<snow_night>
<in>0.0</in>
<cm>0.0</cm>
</snow_night>
<maxwind>
<mph>10</mph>
<kph>16</kph>
<dir>WSW</dir>
<degrees>253</degrees>
</maxwind>
<avewind>
<mph>8</mph>
<kph>13</kph>
<dir>WSW</dir>
<degrees>253</degrees>
</avewind>
<avehumidity>81</avehumidity>
<maxhumidity>0</maxhumidity>
<minhumidity>0</minhumidity>
</forecastday>

<forecastday>
<date>
<epoch>1409162400</epoch>
<pretty_short>7:00 PM WEST</pretty_short>
<pretty>7:00 PM WEST on August 27, 2014</pretty>
<day>27</day>
<month>8</month>
<year>2014</year>
<yday>238</yday>
<hour>19</hour>
<min>00</min>
<sec>0</sec>
<isdst>1</isdst>
<monthname>August</monthname>
<monthname_short>Aug</monthname_short>
<weekday_short>Wed</weekday_short>
<weekday>Wednesday</weekday>
<ampm>PM</ampm>
<tz_short>WEST</tz_short>
<tz_long>Europe/Lisbon</tz_long>
</date>
<period>4</period>
<high>
<fahrenheit>76</fahrenheit>
<celsius>24</celsius>
</high>
<low>
<fahrenheit>64</fahrenheit>
<celsius>18</celsius>
</low>
<conditions>Partly Cloudy</conditions>

<icon>partlycloudy</icon>
<icon_url>http://icons.wxug.com/i/c/k/partlycloudy.gif</icon_url>
<skyicon></skyicon>
<pop>20</pop>
<qpf_allday>
<in>0.00</in>
<mm>0</mm>
</qpf_allday>
<qpf_day>
<in>0.00</in>
<mm>0</mm>
</qpf_day>
<qpf_night>
<in>0.00</in>
<mm>0</mm>
</qpf_night>
<snow_allday>
<in>0.0</in>
<cm>0.0</cm>
</snow_allday>
<snow_day>
<in>0.0</in>
<cm>0.0</cm>
</snow_day>
<snow_night>
<in>0.0</in>
<cm>0.0</cm>
</snow_night>
<maxwind>
<mph>10</mph>
<kph>16</kph>
<dir>W</dir>
<degrees>268</degrees>
</maxwind>
<avewind>
<mph>8</mph>
<kph>13</kph>
<dir>W</dir>
<degrees>268</degrees>
</avewind>
<avehumidity>78</avehumidity>
<maxhumidity>0</maxhumidity>
<minhumidity>0</minhumidity>
</forecastday>

</forecastdays>
</simpleforecast>
</forecast>
 
Aerowinder
Old
(Last edited by Aerowinder; 24th August 2014 at 11:36 PM.)
#6  
Recognized Contributor
Thanks Meter 1,229
Posts: 3,104
Join Date: Aug 2012
Quote:
Originally Posted by cesar.maranhao View Post
there you go.. how do you think i can do this? i have put in bold a small segment i want to retrieve
If Tasker supports RegEx, that would be the way to do it. But I don't know if it does, so I'll assume it does not.


The layout is basic XML. You want <fcttext_metric> that is nested inside the first <forecastday> Try using <fcttext_metric><![CDATA[ as a splitter. And then </fcttext_metric> as another splitter. That should leave you with nothing but the text. So if you had an array, your information should be in arr1, arr3, arr5, arrX.
 

Google Firmware: Google
USB Drivers: Google | Mirror
ADB+ADB Drivers: 19.0.2 (4.4.4) + Koush Universal ADB Drivers

TWRP Official: hammerhead | flo
TWRP Holofied: hammerhead | flo

Gapps: jajb

Superuser: Chainfire | Mirror
 
cesar.maranhao
Old
#7  
Member - OP
Thanks Meter 3
Posts: 69
Join Date: Dec 2013
Quote:
Originally Posted by Aerowinder View Post
If Tasker supports RegEx, that would be the way to do it. But I don't know if it does, so I'll assume it does not.


The layout is basic XML. You want <fcttext_metric> that is nested inside the first <forecastday> Try using <fcttext_metric><![CDATA[ as a splitter. And then </fcttext_metric> as another splitter. That should leave you with nothing but the text. So if you had an array, your information should be in arr1, arr3, arr5, arrX.
it did not work. when i use <fcttext_metric><![CDATA[ as a splitter it does not recognise the end result.

the original text is set as local variable %forecast

when i proceed with the variable split with that input and use flash %forecast2, the result is %forecast2

what am i doing wrong?
 
Aerowinder
Old
#8  
Recognized Contributor
Thanks Meter 1,229
Posts: 3,104
Join Date: Aug 2012
Quote:
Originally Posted by cesar.maranhao View Post
it did not work. when i use <fcttext_metric><![CDATA[ as a splitter it does not recognise the end result.

the original text is set as local variable %forecast

when i proceed with the variable split with that input and use flash %forecast2, the result is %forecast2

what am i doing wrong?
Ok, got it working.

The original XML response from the server, the one that you gave me, will be %forecast.

Variable Set: %forecast; To: <long response here>
Variable Split: %forecast; Splitter: <fcttext><![CDATA[
Varialbe Split: %forecast2; Splitter: ]]></fcttext>

Your info is now in %forecast21. After doing this, I see you wanted the metric read out. Same thing, just add _metric to the splits as per the XML file.

A little explanation for how the Splitter is working. It takes %forecast, and splits it into multiple parts. %forecast1, %forecast2, %forecast3, %forecast4, etc. For as many splits as it will find, it will keep incrementing the number. Through trial and error, we find the information that you desire is in %forecast2. I tested this by using Tasker to Flash: %forecast2. It creates a toast with the variable's value.

So now that we know we want %forecast2, we need to split it again. So we did. And we can't forget to increment. %forecast21, %forecast22, %forecast23, etc.

Again, by Flash, we can see that the information we want is in %forecast21.

Any questions?
 

Google Firmware: Google
USB Drivers: Google | Mirror
ADB+ADB Drivers: 19.0.2 (4.4.4) + Koush Universal ADB Drivers

TWRP Official: hammerhead | flo
TWRP Holofied: hammerhead | flo

Gapps: jajb

Superuser: Chainfire | Mirror
The Following User Says Thank You to Aerowinder For This Useful Post: [ Click to Expand ]
 
cesar.maranhao
Old
#9  
Member - OP
Thanks Meter 3
Posts: 69
Join Date: Dec 2013
Quote:
Originally Posted by Aerowinder View Post
Ok, got it working.

The original XML response from the server, the one that you gave me, will be %forecast.

Variable Set: %forecast; To: <long response here>
Variable Split: %forecast; Splitter: <fcttext><![CDATA[
Varialbe Split: %forecast2; Splitter: ]]></fcttext>

Your info is now in %forecast21. After doing this, I see you wanted the metric read out. Same thing, just add _metric to the splits as per the XML file.

A little explanation for how the Splitter is working. It takes %forecast, and splits it into multiple parts. %forecast1, %forecast2, %forecast3, %forecast4, etc. For as many splits as it will find, it will keep incrementing the number. Through trial and error, we find the information that you desire is in %forecast2. I tested this by using Tasker to Flash: %forecast2. It creates a toast with the variable's value.

So now that we know we want %forecast2, we need to split it again. So we did. And we can't forget to increment. %forecast21, %forecast22, %forecast23, etc.

Again, by Flash, we can see that the information we want is in %forecast21.

Any questions?
Thanks. I was setting the splitter the wrong way. It is now working properly. Cheers

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes