hacker-news: Fix using, fix bug printing HN company posts. Refactor a bit
parent
92a0e1e701
commit
639952a1de
|
@ -1,26 +1,26 @@
|
||||||
! Copyright (C) 2012 Doug Coleman.
|
! Copyright (C) 2012 Doug Coleman.
|
||||||
! 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 hashtables http.client io
|
colors.hex combinators concurrency.combinators formatting fry
|
||||||
io.styles json json.reader kernel make math math.parser
|
hashtables http.client io io.styles json json.reader kernel make
|
||||||
sequences splitting ui urls ;
|
math math.parser sequences splitting ui urls ;
|
||||||
IN: hacker-news
|
IN: hacker-news
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: json-null>f ( obj -- obj/f )
|
: hacker-news-recent-ids ( -- seq )
|
||||||
dup json-null = [ drop f ] when ;
|
"https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
|
||||||
|
http-get nip json> ;
|
||||||
|
|
||||||
: hacker-news-items ( n -- seq )
|
: hacker-news-id>json-url ( n -- url )
|
||||||
[
|
number>string
|
||||||
"https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
|
"https://hacker-news.firebaseio.com/v0/item/" ".json?print=pretty" surround ;
|
||||||
http-get nip json>
|
|
||||||
] dip head
|
: hacker-news-items ( seq -- seq' )
|
||||||
[
|
[ hacker-news-id>json-url http-get nip json> ] parallel-map ;
|
||||||
number>string
|
|
||||||
"https://hacker-news.firebaseio.com/v0/item/" ".json?print=pretty" surround
|
: hacker-news-recent-items ( n -- seq )
|
||||||
http-get nip json>
|
[ hacker-news-recent-ids ] dip head hacker-news-items ;
|
||||||
] parallel-map ;
|
|
||||||
|
|
||||||
: write-title ( title url -- )
|
: write-title ( title url -- )
|
||||||
'[
|
'[
|
||||||
|
@ -57,9 +57,13 @@ PRIVATE>
|
||||||
[ dup "by" of [ " by " write-text [ "by" of ] [ post>user-url ] bi write-link ] [ drop ] if ]
|
[ dup "by" of [ " by " write-text [ "by" of ] [ post>user-url ] bi write-link ] [ drop ] if ]
|
||||||
! [ dup postedAgo>> [ " " write-text postedAgo>> write-text ] [ drop ] if ]
|
! [ dup postedAgo>> [ " " write-text postedAgo>> write-text ] [ drop ] if ]
|
||||||
[
|
[
|
||||||
" | " write-text
|
dup "decendants" of [
|
||||||
[ "descendants" of [ "discuss" ] [ "%d comments" sprintf ] if-zero ]
|
" | " write-text
|
||||||
[ post>comments-url ] bi write-link nl nl
|
[ "descendants" of [ "discuss" ] [ "%d comments" sprintf ] if-zero ]
|
||||||
|
[ post>comments-url ] bi write-link
|
||||||
|
] [
|
||||||
|
drop
|
||||||
|
] if nl nl
|
||||||
]
|
]
|
||||||
} cleave ;
|
} cleave ;
|
||||||
|
|
||||||
|
@ -74,6 +78,6 @@ PRIVATE>
|
||||||
} assoc-union format nl ;
|
} assoc-union format nl ;
|
||||||
|
|
||||||
: hacker-news. ( -- )
|
: hacker-news. ( -- )
|
||||||
25 hacker-news-items
|
30 hacker-news-recent-items
|
||||||
banner.
|
banner.
|
||||||
[ 1 + post. ] each-index ;
|
[ 1 + post. ] each-index ;
|
||||||
|
|
Loading…
Reference in New Issue