hacker-news: Fix hacker-news. for job ads.
parent
b6ff02f53b
commit
350bf5d316
|
@ -2,13 +2,27 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors assocs classes.tuple colors.constants
|
USING: accessors assocs classes.tuple colors.constants
|
||||||
colors.hex combinators formatting fry http.client io io.styles
|
colors.hex combinators formatting fry http.client io io.styles
|
||||||
json.reader kernel make math sequences splitting urls ;
|
json.reader kernel make math sequences splitting urls json
|
||||||
|
math.parser ;
|
||||||
IN: hacker-news
|
IN: hacker-news
|
||||||
|
|
||||||
TUPLE: post title postedBy points id url commentCount postedAgo ;
|
TUPLE: post title postedBy points id url commentCount postedAgo ;
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
: json-null>f ( obj -- obj/f )
|
||||||
|
dup json-null = [ drop f ] when ;
|
||||||
|
|
||||||
: items> ( seq -- seq' )
|
: items> ( seq -- seq' )
|
||||||
[ \ post from-slots ] map ;
|
[
|
||||||
|
\ post from-slots
|
||||||
|
[ json-null>f ] change-postedAgo
|
||||||
|
[ json-null>f ] change-postedBy
|
||||||
|
dup url>> "/comments" head? [
|
||||||
|
dup url>> "/" split last string>number >>id
|
||||||
|
"self" >>url
|
||||||
|
] when
|
||||||
|
] map ;
|
||||||
|
|
||||||
: hacker-news-items ( -- seq )
|
: hacker-news-items ( -- seq )
|
||||||
"http://api.ihackernews.com/page" http-get nip
|
"http://api.ihackernews.com/page" http-get nip
|
||||||
|
@ -35,17 +49,26 @@ TUPLE: post title postedBy points id url commentCount postedAgo ;
|
||||||
: post>comments-url ( post -- user-url )
|
: post>comments-url ( post -- user-url )
|
||||||
id>> "http://news.ycombinator.com/item?id=%d" sprintf >url ;
|
id>> "http://news.ycombinator.com/item?id=%d" sprintf >url ;
|
||||||
|
|
||||||
|
! Api is funky, gives id=0 and /comment/2342342 for self-post ads
|
||||||
|
: post>url ( post -- url )
|
||||||
|
dup url>> "self" = [
|
||||||
|
post>comments-url
|
||||||
|
] [
|
||||||
|
url>> >url
|
||||||
|
] if ;
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
: post. ( post index -- )
|
: post. ( post index -- )
|
||||||
"%2d. " sprintf write-text {
|
"%2d. " sprintf write-text {
|
||||||
[ [ title>> ] [ url>> ] bi write-title ]
|
[ [ title>> ] [ post>url ] bi write-title ]
|
||||||
[ url>> >url host>> " (" ")" surround write-text nl ]
|
[ post>url host>> " (" ")" surround write-text nl ]
|
||||||
[ points>> " %d points" sprintf write-text ]
|
[ points>> " %d points" sprintf write-text ]
|
||||||
[ " by " write-text [ postedBy>> ] [ post>user-url ] bi write-link ]
|
[ dup postedBy>> [ " by " write-text [ postedBy>> ] [ post>user-url ] bi write-link ] [ drop ] if ]
|
||||||
[ " " write-text postedAgo>> write-text ]
|
[ dup postedAgo>> [ " " write-text postedAgo>> write-text ] [ drop ] if ]
|
||||||
[
|
[
|
||||||
" | " write-text
|
" | " write-text
|
||||||
[ commentCount>> "%d comments" sprintf ]
|
[ commentCount>> [ "discuss" ] [ "%d comments" sprintf ] if-zero ]
|
||||||
[ post>comments-url ] bi write-link nl nl
|
[ post>comments-url ] bi write-link nl nl
|
||||||
]
|
]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
Loading…
Reference in New Issue