Sunday, May 12, 2013

[Tasker] Check a website for specific information

One useful thing Tasker can do is fetch a website and scan it for specific information you are interested in. If the information you are looking for is present, Tasker can notify you and your friends. After clicking on the notification you will be redirected to the information of interest.

I want to show you how to check a bargain website like mydealz.de for posts containing the keywords "Kino" (Cinema in German) and "Knaller" (price hit) and notify you and your friends about them. Deals posted with the keyword cinema often contain information on how to get a discount for a certain movie or how to watch it for free. Often the amount of discounted tickets is limited so one has to react quickly to get one. It can be a huge advantage to know about this deals as soon as possible. So lets make Tasker look out for these discounts and inform us about the interesting ones!

In principle the task is build like this: We have a global variable which contains all the interesting keywords separated by a semicolon ";". In out example the Variable is called "%WANTED" and has the value "Kino;Knaller". Of cource it can contain more keywords, just separate them correctly. The task downloads the html file of the website by using the HTTP GET command and reads it in into a new local variable %mydealz. Afterwards the variable %mydealz is searched with regular expressions for headings. All the headings are saved in an array. If a keyword occurs in a heading a notification is shown and a SMS is sent to provided numbers.

Here the code description:
MyDealz check
A1: Variable Query [ Title:What are the keywords to look for? (Semicolon separated) Variable:%WANTED Input Type:Normal Text Default:SSD;Plasma;House Background Image: Layout:Variable Query Timeout (Seconds):300 Show Over Keyguard:Off ] If [ %WANTED ! Set ]
A2: Variable Set [ Name:%wanted To:%WANTED Do Maths:Off Append:Off ]
A3: Variable Split [ Name:%wanted Splitter:; Delete Base:Off ]
A4: HTTP Get [ Server:Port:www.mydealz.de Path: Attributes: Cookies: Timeout:30 Mime Type:application/octet-stream Output File:Tasker/log/MyDealz.html ]
A5: Read File [ File:Tasker/log/MyDealz.html To Var:%mydealz ]
A6: Variable Search Replace [ Variable:%mydealz Search:<h2>
<a href="http://www.blogger.com/.*">.*</a></h2>
A7: For [ Variable:%element Items:%wanted() ]
A8: For [ Variable:%num Items:%array() ]
A9: If [ %num ~R %element ]
A10: Variable Convert [ Name:%num Function:HTML to Text Store Result In:%mydealztext ]
A11: Variable Search Replace [ Variable:%num Search:".*" Ignore Case:Off Multi-Line:On One Match Only:On Store Matches In:%MYDEALZ_NOTIFY_URL Replace Matches:Off Replace With: ]
A12: Test [ Type:Variable Length Data:%MYDEALZ_NOTIFY_URL1 Store Result In:%urllength ]
A13: Variable Subtract [ Name:%urllength Value:2 ]
A14: Variable Section [ Name:%MYDEALZ_NOTIFY_URL1 From:2 Length:%urllength Adapt To Fit:Off Store Result In:%MYDEALZ_NOTIFY_URL1 ] If [ %MYDEALZ_NOTIFY_URL1 ~R " ]
A15: Variable Convert [ Name:%num Function:To MD5 Digest Store Result In:%num ]
A16: For [ Variable:%allreadyfound Items:%MYDEALZFOUND() ]
A17: If [ %allreadyfound ~ %num ]
A18: Goto [ Type:Action Label Number:1 Label:next ]
A19: End If
A20: End For
A21: Array Push [ Name:%MYDEALZFOUND Position:1 Value:%num Fill Spaces:On ]
A22: Variable Clear [ Name:%MYDEALZFOUND4 Pattern Matching:Off ]
A23: Variable Set [ Name:%MYDEALZ_NOTIFY To:%element bei myDealz Do Maths:Off Append:Off ]
A24: Notify Sound [ Title:%element bei myDealz Text:%mydealztext Icon:ipack:ilikebuttonshd:perspectivebutton_reboot Number:0 Sound File:/system/media/audio/alarms/Serene_morning.ogg Priority:3 ]
A25: Perform Task [ Name:SMS send Stop:Off Priority:5 Parameter 1 (%par1):%element on myDealz: %NEWLINE%mydealztext %MYDEALZ_NOTIFY_URL1 Parameter 2 (%par2):0123456789 Return Value Variable: ]
A26: End If
<next>
A27: Anchor
A28: End For
A29: End For 
The task is long, so I provide here a XML file for you to import it directly into Tasker. Just save the file on your phone. Open Tasker, long press on Tasks, choose Import and navigate to the path where you saved the file. Check the imported task.

You can run the task whenever you want, for example every hour or every time you are connected to a WiFi network. Enjoy and don't miss a deal any more :)

Download or copy paste into a file named "MyDealtCheck.tsk.xml" the following code:
Click to expand the code
<TaskerData sr="" dvi="1" tv="1.3.3u2m">
<Task sr="task170">
<cdate>1358719750905</cdate>
<edate>1368371947116</edate>
<id>170</id>
<nme>MyDealz check</nme>
<pri>10</pri>
<Kid sr="Kid">
<launchID>131</launchID>
<pkg>com.gmail.bennylinnik.mydealzcheck</pkg>
<vnme>1.0</vnme>
<vnum>2</vnum>
</Kid>
<Action sr="act0" ve="3">
<code>595</code>
<lhs>%WANTED</lhs>
<op>10</op>
<rhs></rhs>
<Str sr="arg0" ve="3">What shall I look for?</Str>
<Str sr="arg1" ve="3">%WANTED</Str>
<Int sr="arg2" val="0"/>
<Str sr="arg3" ve="3">SSD;Plasma;Kino</Str>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3">Variable Query</Str>
<Int sr="arg6" val="300"/>
<Int sr="arg7" val="0"/>
</Action>
<Action sr="act1" ve="3">
<code>547</code>
<Str sr="arg0" ve="3">%wanted</Str>
<Str sr="arg1" ve="3">%WANTED</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act10" ve="3">
<code>598</code>
<Str sr="arg0" ve="3">%num</Str>
<Str sr="arg1" ve="3">".*"</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="1"/>
<Int sr="arg4" val="1"/>
<Str sr="arg5" ve="3">%MYDEALZ_NOTIFY_URL</Str>
<Int sr="arg6" val="0"/>
<Str sr="arg7" ve="3"/>
</Action>
<Action sr="act11" ve="3">
<code>115</code>
<Int sr="arg0" val="11"/>
<Str sr="arg1" ve="3">%MYDEALZ_NOTIFY_URL1</Str>
<Str sr="arg2" ve="3">%urllength</Str>
</Action>
<Action sr="act12" ve="3">
<code>890</code>
<Str sr="arg0" ve="3">%urllength</Str>
<Int sr="arg1" val="2"/>
</Action>
<Action sr="act13" ve="3">
<code>597</code>
<lhs>%MYDEALZ_NOTIFY_URL1</lhs>
<op>11</op>
<rhs>"</rhs>
<Str sr="arg0" ve="3">%MYDEALZ_NOTIFY_URL1</Str>
<Int sr="arg1" val="2"/>
<Int sr="arg2">
<var>%urllength</var>
</Int>
<Int sr="arg3" val="0"/>
<Str sr="arg4" ve="3">%MYDEALZ_NOTIFY_URL1</Str>
</Action>
<Action sr="act14" ve="3">
<code>596</code>
<Str sr="arg0" ve="3">%num</Str>
<Int sr="arg1" val="26"/>
<Str sr="arg2" ve="3">%num</Str>
</Action>
<Action sr="act15" ve="3">
<code>39</code>
<Str sr="arg0" ve="3">%allreadyfound</Str>
<Str sr="arg1" ve="3">%MYDEALZFOUND()</Str>
</Action>
<Action sr="act16" ve="3">
<code>37</code>
<lhs>%allreadyfound</lhs>
<op>1</op>
<rhs>%num</rhs>
</Action>
<Action sr="act17" ve="3">
<code>135</code>
<Int sr="arg0" val="1"/>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">next</Str>
</Action>
<Action sr="act18" ve="3">
<code>38</code>
</Action>
<Action sr="act19" ve="3">
<code>40</code>
</Action>
<Action sr="act2" ve="3">
<code>590</code>
<Str sr="arg0" ve="3">%wanted</Str>
<Str sr="arg1" ve="3">;</Str>
<Int sr="arg2" val="0"/>
</Action>
<Action sr="act20" ve="3">
<code>355</code>
<Str sr="arg0" ve="3">%MYDEALZFOUND</Str>
<Int sr="arg1" val="1"/>
<Str sr="arg2" ve="3">%num</Str>
<Int sr="arg3" val="1"/>
</Action>
<Action sr="act21" ve="3">
<code>549</code>
<Str sr="arg0" ve="3">%MYDEALZFOUND4</Str>
<Int sr="arg1" val="0"/>
</Action>
<Action sr="act22" ve="3">
<code>547</code>
<Str sr="arg0" ve="3">%MYDEALZ_NOTIFY</Str>
<Str sr="arg1" ve="3">%element bei myDealz</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
</Action>
<Action sr="act23" ve="3">
<code>538</code>
<Str sr="arg0" ve="3">%element bei myDealz</Str>
<Str sr="arg1" ve="3">%mydealztext</Str>
<Img sr="arg2" ve="2">
<icn>2130837538</icn>
</Img>
<Int sr="arg3" val="0"/>
<Str sr="arg4" ve="3">/system/media/audio/alarms/Serene_morning.ogg</Str>
<Int sr="arg5" val="3"/>
</Action>
<Action sr="act24" ve="3">
<code>41</code>
<Str sr="arg0" ve="3">0123456789</Str>
<Str sr="arg1" ve="3">%element on myDealz:
%mydealztext %MYDEALZ_NOTIFY_URL1</Str>
<Int sr="arg2" val="0"/>
</Action>
<Action sr="act25" ve="3">
<code>38</code>
</Action>
<Action sr="act26" ve="3">
<code>300</code>
<label>next</label>
</Action>
<Action sr="act27" ve="3">
<code>40</code>
</Action>
<Action sr="act28" ve="3">
<code>40</code>
</Action>
<Action sr="act3" ve="3">
<code>118</code>
<Str sr="arg0" ve="3">www.mydealz.de</Str>
<Str sr="arg1" ve="3"/>
<Str sr="arg2" ve="3"/>
<Str sr="arg3" ve="3"/>
<Int sr="arg4" val="30"/>
<Str sr="arg5" ve="3">application/octet-stream</Str>
<Str sr="arg6" ve="3">Tasker/log/MyDealz.html</Str>
</Action>
<Action sr="act4" ve="3">
<code>417</code>
<Str sr="arg0" ve="3">Tasker/log/MyDealz.html</Str>
<Str sr="arg1" ve="3">%mydealz</Str>
</Action>
<Action sr="act5" ve="3">
<code>598</code>
<Str sr="arg0" ve="3">%mydealz</Str>
<Str sr="arg1" ve="3">&lt;h2&gt;&lt;a href=".*"&gt;.*&lt;/a&gt;&lt;/h2&gt;</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
<Int sr="arg4" val="0"/>
<Str sr="arg5" ve="3">%array</Str>
<Int sr="arg6" val="0"/>
<Str sr="arg7" ve="3"/>
</Action>
<Action sr="act6" ve="3">
<code>39</code>
<Str sr="arg0" ve="3">%element</Str>
<Str sr="arg1" ve="3">%wanted()</Str>
</Action>
<Action sr="act7" ve="3">
<code>39</code>
<Str sr="arg0" ve="3">%num</Str>
<Str sr="arg1" ve="3">%array()</Str>
</Action>
<Action sr="act8" ve="3">
<code>37</code>
<lhs>%num</lhs>
<op>11</op>
<rhs>%element</rhs>
</Action>
<Action sr="act9" ve="3">
<code>596</code>
<Str sr="arg0" ve="3">%num</Str>
<Int sr="arg1" val="7"/>
<Str sr="arg2" ve="3">%mydealztext</Str>
</Action>
<Img sr="icn" ve="2">
<icn>2130837538</icn>
</Img>
</Task>
</TaskerData>

1 comment:

  1. good morning and good luck spirit? Thank you for the information

    ReplyDelete