bddc524aae539204ebe025345f54ad1f8f0d541a
8 from twitter
.util
import printNicely
9 from StringIO
import StringIO
10 from dateutil
import parser
11 from .c_image
import *
19 def color_func(func_name
):
21 Call color function base on name
23 pure
= func_name
.encode('utf8')
27 def draw(t
, iot
=False, keyword
=None, fil
=[], ig
=[]):
35 screen_name
= t
['user']['screen_name']
36 name
= t
['user']['name']
37 created_at
= t
['created_at']
38 favorited
= t
['favorited']
39 date
= parser
.parse(created_at
)
40 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
41 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
47 urls
= t
['entities']['urls']
49 expanded_url
.append(u
['expanded_url'])
58 media
= t
['entities']['media']
60 media_url
.append(m
['media_url'])
65 screen_name
= '@' + screen_name
66 if fil
and screen_name
not in fil
:
68 if ig
and screen_name
in ig
:
72 res
= db
.tweet_to_rainbow_query(tid
)
75 res
= db
.tweet_to_rainbow_query(tid
)
76 rid
= res
[0].rainbow_id
79 user
= cycle_color(name
) + color_func(TWEET
['nick'])(' ' + screen_name
+ ' ')
80 meta
= color_func(TWEET
['clock'])('[' + clock
+ '] ') + color_func(TWEET
['id'])('[id=' + str(rid
) + '] ')
82 meta
= meta
+ color_func(TWEET
['favorite'])(u
'\u2605')
86 for index
in range(len(expanded_url
)):
88 lambda x
: expanded_url
[index
] if x
== url
[index
] else x
,
91 tweet
= map(lambda x
: color_func(TWEET
['rt'])(x
) if x
== 'RT' else x
, tweet
)
92 # Highlight screen_name
93 tweet
= map(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, tweet
)
95 tweet
= map(lambda x
: color_func(TWEET
['link'])(x
) if x
[0:4] == 'http' else x
, tweet
)
96 # Highlight search keyword
99 lambda x
: color_func(TWEET
['keyword'])(x
) if
100 ''.join(c
for c
in x
if c
.isalnum()).lower() == keyword
.lower()
105 tweet
= ' '.join(tweet
)
108 line1
= u
"{u:>{uw}}:".format(
112 line2
= u
"{c:>{cw}}".format(
124 if iot
and media_url
:
126 response
= requests
.get(mu
)
127 image_to_display(StringIO(response
.content
))
130 def print_message(m
):
134 sender_screen_name
= '@' + m
['sender_screen_name']
135 sender_name
= m
['sender']['name']
137 recipient_screen_name
= '@' + m
['recipient_screen_name']
138 recipient_name
= m
['recipient']['name']
140 date
= parser
.parse(m
['created_at'])
141 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
142 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
145 res
= db
.message_to_rainbow_query(mid
)
147 db
.message_store(mid
)
148 res
= db
.message_to_rainbow_query(mid
)
149 rid
= res
[0].rainbow_id
152 sender
= cycle_color(sender_name
) + color_func(MESSAGE
['sender'])(' ' + sender_screen_name
+ ' ')
153 recipient
= cycle_color(recipient_name
) + color_func(MESSAGE
['recipient'])(' ' + recipient_screen_name
+ ' ')
154 user
= sender
+ color_func(MESSAGE
['to'])(' >>> ') + recipient
155 meta
= color_func(MESSAGE
['clock'])('[' + clock
+ ']') + color_func(MESSAGE
['id'])(' [message_id=' + str(rid
) + '] ')
156 text
= ''.join(map(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
158 line1
= u
"{u:>{uw}}:".format(
162 line2
= u
"{c:>{cw}}".format(
175 def show_profile(u
, iot
=False):
181 screen_name
= u
['screen_name']
182 description
= u
['description']
183 profile_image_url
= u
['profile_image_url']
184 location
= u
['location']
186 created_at
= u
['created_at']
187 statuses_count
= u
['statuses_count']
188 friends_count
= u
['friends_count']
189 followers_count
= u
['followers_count']
192 statuses_count
= color_func(PROFILE
['statuses_count'])(str(statuses_count
) + ' tweets')
193 friends_count
= color_func(PROFILE
['friends_count'])(str(friends_count
) + ' following')
194 followers_count
= color_func(PROFILE
['followers_count'])(str(followers_count
) + ' followers')
195 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
196 user
= cycle_color(name
) + color_func(PROFILE
['nick']()' @' + screen_name
+ ' : ') + count
197 profile_image_raw_url
= 'Profile photo: ' + color_func(PROFILE
['profile_image_url'])(profile_image_url
)
198 description
= ''.join(
199 map(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
200 description
= color_func(PROFILE
['description'])(description
)
201 location
= 'Location : ' + color_func(PROFILE
['location'])(location
)
202 url
= 'URL : ' + (color_func(PROFILE
['url'])(url
) if url
else '')
203 date
= parser
.parse(created_at
)
204 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
205 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
206 clock
= 'Join at ' + color_func(PROFILE
['clock'])(clock
)
209 line1
= u
"{u:>{uw}}".format(
213 line2
= u
"{p:>{pw}}".format(
214 p
=profile_image_raw_url
,
215 pw
=len(profile_image_raw_url
) + 4,
217 line3
= u
"{d:>{dw}}".format(
219 dw
=len(description
) + 4,
221 line4
= u
"{l:>{lw}}".format(
223 lw
=len(location
) + 4,
225 line5
= u
"{u:>{uw}}".format(
229 line6
= u
"{c:>{cw}}".format(
238 response
= requests
.get(profile_image_url
)
239 image_to_display(StringIO(response
.content
), 2, 20)
242 for line
in [line3
, line4
, line5
, line6
]:
247 def print_trends(trends
):
251 for topic
in trends
[:TREND_MAX
]:
254 line
= cycle_color(name
) + ': ' + TREND
['url'](url
)