factor/extra/twitter/prettyprint/prettyprint.factor

78 lines
2.2 KiB
Factor
Raw Permalink Normal View History

USING: accessors continuations fry http.client images.loader
images.loader.private images.viewer io io.styles kernel memoize
2014-02-12 23:12:54 -05:00
prettyprint sequences twitter assocs ;
IN: twitter.prettyprint
MEMO: load-http-image ( url -- image/f )
'[ _
[ http-get nip ] [ image-class ] bi load-image*
] [ drop f ] recover ;
: user-image ( user -- image/f )
profile-image-url>> load-http-image ;
CONSTANT: tweet-table-style
H{ { table-gap { 5 5 } } }
CONSTANT: tweet-username-style
H{
{ font-style bold }
}
CONSTANT: tweet-text-style
H{
{ font-name "sans-serif" }
2010-06-27 17:16:41 -04:00
{ font-size 16 }
{ wrap-margin 500 }
}
CONSTANT: tweet-metadata-style
H{
{ font-size 10 }
}
2014-02-12 23:12:54 -05:00
: profile. ( user -- )
tweet-table-style [
[
[ dup "profile_image_url" of load-http-image image. ] with-cell
[
tweet-username-style [
dup "name" of write nl
dup "screen_name" of write
] with-style
] with-cell
] with-row
] tabular-output nl
drop ;
: tweet. ( status -- )
tweet-table-style [
[
[ dup user>> user-image [ image. ] when* ] with-cell
[
2010-06-27 17:16:41 -04:00
H{ { wrap-margin 600 } } [
tweet-text-style [
tweet-username-style [
dup user>> screen-name>> write
] with-style
2013-03-14 22:24:00 -04:00
bl dup text>> print
2010-06-27 17:16:41 -04:00
tweet-metadata-style [
dup created-at>> write
" via " write
dup source>> write
] with-style
] with-style
] with-nesting
] with-cell
] with-row
] tabular-output nl
drop ;
2014-02-12 23:12:54 -05:00
: user-profile. ( user -- ) user-profile profile. ;
2014-02-12 19:55:31 -05:00
: friends-timeline. ( -- ) friends-timeline [ tweet. ] each ;
: public-timeline. ( -- ) public-timeline [ tweet. ] each ;
: user-timeline. ( user -- ) user-timeline [ tweet. ] each ;
: home-timeline. ( -- ) home-timeline [ tweet. ] each ;
: mentions-timeline. ( -- ) mentions-timeline [ tweet. ] each ;