annotate tests/reddit.ur @ 21:7275f59cab61
tagAOR and a Reddit example of using it
author |
Adam Chlipala <adam@chlipala.net> |
date |
Sat, 29 Sep 2012 10:30:00 -0400 |
parents |
|
children |
923e097e9ba3 |
rev |
line source |
adam@21
|
1 fun main () =
|
adam@21
|
2 doc <- Feed.fetch "http://www.reddit.com/?limit=30";
|
adam@21
|
3
|
adam@21
|
4 acc <- Feed.app' (Feed.tree (Feed.tagAOR "div" {DataUps = "data-ups", Class = "class"} {Style = "style"})
|
adam@21
|
5 (Feed.tagAO "a" {Class = "class", Style = "style", Href = "href"}))
|
adam@21
|
6 (fn (div, a) (count, list) =>
|
adam@21
|
7 return (case a.Href of
|
adam@21
|
8 None => (count, list)
|
adam@21
|
9 | Some link =>
|
adam@21
|
10 if count >= 30
|
adam@21
|
11 || not (String.isPrefix {Full = div.Class, Prefix = " thing "})
|
adam@21
|
12 || Option.isSome (String.sindex {Haystack = div.Class, Needle = "promoted"})
|
adam@21
|
13 || div.Style = Some "display:none"
|
adam@21
|
14 || a.Class <> Some "title "
|
adam@21
|
15 || a.Style = Some "display:none" then
|
adam@21
|
16 (count, list)
|
adam@21
|
17 else
|
adam@21
|
18 (count + 1, link :: list)))
|
adam@21
|
19 doc (0, []);
|
adam@21
|
20
|
adam@21
|
21 return <xml><body>
|
adam@21
|
22 <h1>Top 30 Reddit Links</h1>
|
adam@21
|
23
|
adam@21
|
24 <ol>
|
adam@21
|
25 {List.mapX (fn url => <xml><li>{[url]}</li></xml>) (List.rev acc.2)}
|
adam@21
|
26 </ol>
|
adam@21
|
27 </body></xml>
|