702ca1d983764866182eb323c029ed95ff231e2e
8 from StringIO
import StringIO
9 from dateutil
import parser
16 def draw(t
, iot
=False, keyword
=None, fil
=[], ig
=[]):
24 screen_name
= t
['user']['screen_name']
25 name
= t
['user']['name']
26 created_at
= t
['created_at']
27 favorited
= t
['favorited']
28 date
= parser
.parse(created_at
)
29 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
30 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
36 urls
= t
['entities']['urls']
38 expanded_url
.append(u
['expanded_url'])
47 media
= t
['entities']['media']
49 media_url
.append(m
['media_url'])
54 screen_name
= '@' + screen_name
55 if fil
and screen_name
not in fil
:
57 if ig
and screen_name
in ig
:
61 res
= db
.tweet_to_rainbow_query(tid
)
64 res
= db
.tweet_to_rainbow_query(tid
)
65 rid
= res
[0].rainbow_id
68 user
= cycle_color(name
) + grey(' ' + screen_name
+ ' ')
69 meta
= grey('[' + clock
+ '] [id=' + str(rid
) + '] ')
71 meta
= meta
+ green(u
'\u2605')
75 for index
in range(len(expanded_url
)):
77 lambda x
: expanded_url
[index
] if x
== url
[index
] else x
,
80 tweet
= map(lambda x
: grey(x
) if x
== 'RT' else x
, tweet
)
81 # Highlight screen_name
82 tweet
= map(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, tweet
)
84 tweet
= map(lambda x
: cyan(x
) if x
[0:4] == 'http' else x
, tweet
)
85 # Highlight search keyword
88 lambda x
: on_yellow(x
) if
89 ''.join(c
for c
in x
if c
.isalnum()).lower() == keyword
.lower()
94 tweet
= ' '.join(tweet
)
97 line1
= u
"{u:>{uw}}:".format(
101 line2
= u
"{c:>{cw}}".format(
113 if iot
and media_url
:
115 response
= requests
.get(mu
)
116 image_to_display(StringIO(response
.content
))
119 def print_message(m
):
123 sender_screen_name
= '@' + m
['sender_screen_name']
124 sender_name
= m
['sender']['name']
126 recipient_screen_name
= '@' + m
['recipient_screen_name']
127 recipient_name
= m
['recipient']['name']
129 date
= parser
.parse(m
['created_at'])
130 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
131 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
134 res
= db
.message_to_rainbow_query(mid
)
136 db
.message_store(mid
)
137 res
= db
.message_to_rainbow_query(mid
)
138 rid
= res
[0].rainbow_id
140 sender
= cycle_color(sender_name
) + grey(' ' + sender_screen_name
+ ' ')
141 recipient
= cycle_color(
142 recipient_name
) + grey(' ' + recipient_screen_name
+ ' ')
143 user
= sender
+ magenta(' >>> ') + recipient
144 meta
= grey('[' + clock
+ '] [message_id=' + str(rid
) + '] ')
145 text
= ''.join(map(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
147 line1
= u
"{u:>{uw}}:".format(
151 line2
= u
"{c:>{cw}}".format(
164 def show_profile(u
, iot
=False):
170 screen_name
= u
['screen_name']
171 description
= u
['description']
172 profile_image_url
= u
['profile_image_url']
173 location
= u
['location']
175 created_at
= u
['created_at']
176 statuses_count
= u
['statuses_count']
177 friends_count
= u
['friends_count']
178 followers_count
= u
['followers_count']
180 statuses_count
= green(str(statuses_count
) + ' tweets')
181 friends_count
= green(str(friends_count
) + ' following')
182 followers_count
= green(str(followers_count
) + ' followers')
183 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
184 user
= cycle_color(name
) + grey(' @' + screen_name
+ ' : ') + count
185 profile_image_raw_url
= 'Profile photo: ' + cyan(profile_image_url
)
186 description
= ''.join(
187 map(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
188 description
= yellow(description
)
189 location
= 'Location : ' + magenta(location
)
190 url
= 'URL : ' + (cyan(url
) if url
else '')
191 date
= parser
.parse(created_at
)
192 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
193 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
194 clock
= 'Join at ' + white(clock
)
196 line1
= u
"{u:>{uw}}".format(
200 line2
= u
"{p:>{pw}}".format(
201 p
=profile_image_raw_url
,
202 pw
=len(profile_image_raw_url
) + 4,
204 line3
= u
"{d:>{dw}}".format(
206 dw
=len(description
) + 4,
208 line4
= u
"{l:>{lw}}".format(
210 lw
=len(location
) + 4,
212 line5
= u
"{u:>{uw}}".format(
216 line6
= u
"{c:>{cw}}".format(
224 response
= requests
.get(profile_image_url
)
225 image_to_display(StringIO(response
.content
), 2, 20)
228 for line
in [line3
, line4
, line5
, line6
]:
233 def print_trends(trends
):
237 for topic
in trends
[:TREND_MAX
]:
240 line
= cycle_color(name
) + ': ' + cyan(url
)