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