]> gitweb.factorcode.org Git - factor.git/blob - extra/twitter/prettyprint/prettyprint.factor
core, basis, extra: Remove DOS line endings from files.
[factor.git] / extra / twitter / prettyprint / prettyprint.factor
1 USING: accessors continuations fry http.client images.loader
2 images.loader.private images.viewer io io.styles kernel memoize
3 prettyprint sequences twitter assocs ;
4 IN: twitter.prettyprint
5
6 MEMO: load-http-image ( url -- image/f )
7     '[ _
8         [ http-get nip ] [ image-class ] bi load-image*
9     ] [ drop f ] recover ;
10
11 : user-image ( user -- image/f )
12     profile-image-url>> load-http-image ;
13
14 CONSTANT: tweet-table-style
15     H{ { table-gap { 5 5 } } }
16
17 CONSTANT: tweet-username-style
18     H{
19         { font-style bold }
20     }
21
22 CONSTANT: tweet-text-style
23     H{
24         { font-name "sans-serif" }
25         { font-size 16 }
26         { wrap-margin 500 }
27     }
28
29 CONSTANT: tweet-metadata-style
30     H{
31         { font-size 10 }
32     }
33
34 : profile. ( user -- )
35     tweet-table-style [
36         [
37             [ dup "profile_image_url" of load-http-image image. ] with-cell
38             [
39                 tweet-username-style [
40                     dup "name" of write nl
41                     dup "screen_name" of write
42                 ] with-style
43             ] with-cell
44         ] with-row
45     ] tabular-output nl
46     drop ;
47
48 : tweet. ( status -- )
49     tweet-table-style [
50         [
51             [ dup user>> user-image [ image. ] when* ] with-cell
52             [
53                 H{ { wrap-margin 600 } } [
54                     tweet-text-style [
55                         tweet-username-style [
56                             dup user>> screen-name>> write
57                         ] with-style
58                         bl dup text>> print
59
60                         tweet-metadata-style [
61                             dup created-at>> write
62                             " via " write
63                             dup source>> write
64                         ] with-style
65                     ] with-style
66                 ] with-nesting
67             ] with-cell
68         ] with-row
69     ] tabular-output nl
70     drop ;
71
72 : user-profile.      ( user -- ) user-profile      profile. ;
73 : friends-timeline.  ( -- )      friends-timeline  [ tweet. ] each ;
74 : public-timeline.   ( -- )      public-timeline   [ tweet. ] each ;
75 : user-timeline.     ( user -- ) user-timeline     [ tweet. ] each ;
76 : home-timeline.     ( -- )      home-timeline     [ tweet. ] each ;
77 : mentions-timeline. ( -- )      mentions-timeline [ tweet. ] each ;