Tasker: Read you News/Pick Headlines to Display
What does it do?:
This task is set up to pull the headlines from Google News and read them to you. It prefaces every headline with a number. You can then ask it to pull up ‘article #x’ and it will load the URL on your phone.
How does it work?:
This task uses the ‘Variable Split’ feature together with the ‘HTTP Get’ feature. HTTP Get lets you get the source from any URL. Variable Split allows you to parse this data. Pocketables.com did a great tutorial of this. You can find it here
The nitty gritty:
I split the work up into two separate tasks, ‘Headline Reader’ and ‘Article Display’.
1. Set Variable %NewsPiece to 4 <— I’ll get back to this later
2. Set Variable %HeadlineNumber to the value of %NewsPiece – 3
3. HTTP Get (URL of your customized Google News RSS feed, which you can get by going to news.google.com, customizing your news page and pressing the orange RSS logo at the bottom of the page). This command takes the contents of that page and puts it into a variable called %HTTPD
4. Set Variable %News to %HTTPD – This takes whatever is in %HTTPD and pastes it to a new variable called %News. This is not strictly necessary, but I like to do it anyway.
5. Variable Split
– Variable to be split – %News
– Variable splitter – <title>
That’s where it gets interesting. It just splits up the $News variable into a number of variables, wherever the text <title> appears. For example, if the data in $News said:
Hello, <title> welcome to signaltheorist </title> <link> url=http://1.com</link> this is some <title> shameless self promotion </title><link> url=http://2.com </link> <title> the narwhal bacons </title> <link> url=http://3.com </link><title> at midnight </title>
it would split it up into 5 variables (identified by adding a number at the end). In this case the result would be the creation of the following variables:
%News1 – Hello,
%News2 – welcome to signaltheorist </title> <link> url=http://1.com</link> this is some
%News3 – shameless self promotion </title><link> url=http://2.com </link>
%News4 – the narwhal bacons </title><link> url=http://3.com </link>
%News5 – at midnight </title>
Notice that the text <title> disappears. This was the point at which the text was split and it is deleted when a split occurs.
6. Set Variable %NewsSplit to %News(%NewsPiece)
%News(%NewsPiece) will basically be decyphered as %News(the value of %NewsPiece goes here). At the beginning of the task (step 1) we set the value of %NewsPiece to the number 4, so %News(%NewsPiece) will read as %News4.
Therefore, ‘Set Variable %NewsSplit to %News(%NewsPiece)’ in this case will put the contents of %News4 into %NewsSplit. So now %NewsSplit contains the text ‘the narwhal bacons </title><link> url=http://3.com </link>’
So we want to get the pieces of text ‘the narwhal bacons’ and the link ‘http://3.com’ out of this chunk and get rid of the rest of the garbage text.
7. Set Variable %NewsLink to %NewsSplit – as you should know by now, this copies the contents of %NewsSplit to %NewsLink
8. Split Variable %NewsLink at ‘url=’
%NewsLink1 – ‘the narwhal bacons </title><link> url=’
%NewsLink2 – ‘http://3.com </link>’
So we’ve almost isolated ‘http://3.com’, just one more split to make it work
9. Split Variable %NewsLink2 at ‘</link>’
%NewsLink21 – ‘http://3.com’
We now have the link isolated and need to save it as it’s own variable
10. Set Variable %NewsLink21 to %Headline(%HeadlineNumber)
If you remember, in step 2 we set %HeadlineNumber to whatever %NewsPiece is minus 3. In this case, that makes this 1. So %Headline1 now contains the text ‘http://3.com’
Now we want to isolate the text we needed. If you remember, before we went on the tangent of finding the link data, we put the data ‘the narwhal bacons </title><link> url=http://3.com </link>’ into %NewsSplit, so let’s use that to isolate the headline text we need.
11. Variable Split %NewsSplit at ‘</title>’
%NewsSplit1 – ‘the narwhal bacons’
%NewsSplit2 – ‘<link> url=http://3.com </link>
So the data we need is in %NewsSplit1. Let’s save that seperately
12. Set Variable %NewsProcessed(%NewsPiece) to %NewsSplit1
13. Say ‘%HeadlineNumber: %NewsProcessed(%NewsPiece)
In this case that will say aloud ‘1: the narwhal bacons’
14. Set Variable %NewsPiece to %NewsPiece + 1 (you will want to check the ‘do maths’ box)
This increases the value of %NewsPiece by 1, in this case making it ‘5’
15. Go to action #2
This basically restarts the program, but instead grabs the next headline.
Next, we create a program that allows us to make the phone display a certain headline, assigned by number.
1. Say ‘Which headline number did you want?’
2. Run ‘Get Voice’ – This opens up a little prompt that awaits you voice. Say the number of the headline you want now. Let’s assume you said 1. When you use ‘Get Voice’ it stores what it deciphers you saying as %VOICE.
3. IF %VOICE is a number greater than 0
4. Browse to the URL ‘%Headline(%VOICE)’ – in this case, %Headline1
In the last program, we had the URL attached to the first headline assigned to the variable %Headline1, so it will now pull it up and put it into your browser and pop up the resulting page
5. ELSE IF %VOICE = Cancel
(if the result of getting your voice was not a number greater than zero, it will now check if it was ‘Cancel’)
6. STOP – Pretty self explanatory
(if the result is neither a number nor ‘Cancel’)
8. Say ‘Please say the number only’
9. Go to action #2
I’m sure I missed explaining something, feel free to ask!