b35649c2393c66b6614cf8fc985ba07b6a187d31
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 print globals()['TWEET']
24 pure
= func_name
.encode('utf8')
25 if pure
.startswith('RGB_') and pure
[4:].isdigit():
26 return RGB(int(pure
[4:]))
27 return globals()[pure
]
30 def draw(t
, iot
=False, keyword
=None, fil
=[], ig
=[]):
38 screen_name
= t
['user']['screen_name']
39 name
= t
['user']['name']
40 created_at
= t
['created_at']
41 favorited
= t
['favorited']
42 date
= parser
.parse(created_at
)
43 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
44 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
50 urls
= t
['entities']['urls']
52 expanded_url
.append(u
['expanded_url'])
61 media
= t
['entities']['media']
63 media_url
.append(m
['media_url'])
68 screen_name
= '@' + screen_name
69 if fil
and screen_name
not in fil
:
71 if ig
and screen_name
in ig
:
75 res
= db
.tweet_to_rainbow_query(tid
)
78 res
= db
.tweet_to_rainbow_query(tid
)
79 rid
= res
[0].rainbow_id
82 user
= cycle_color(name
) + color_func(c
['TWEET']['nick'])(' ' + screen_name
+ ' ')
83 meta
= color_func(c
['TWEET']['clock'])('[' + clock
+ '] ') + color_func(c
['TWEET']['id'])('[id=' + str(rid
) + '] ')
85 meta
= meta
+ color_func(c
['TWEET']['favorite'])(u
'\u2605')
89 for index
in range(len(expanded_url
)):
91 lambda x
: expanded_url
[index
] if x
== url
[index
] else x
,
94 tweet
= map(lambda x
: color_func(c
['TWEET']['rt'])(x
) if x
== 'RT' else x
, tweet
)
95 # Highlight screen_name
96 tweet
= map(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, tweet
)
98 tweet
= map(lambda x
: color_func(c
['TWEET']['link'])(x
) if x
[0:4] == 'http' else x
, tweet
)
99 # Highlight search keyword
102 lambda x
: color_func(c
['TWEET']['keyword'])(x
) if
103 ''.join(c
for c
in x
if c
.isalnum()).lower() == keyword
.lower()
108 tweet
= ' '.join(tweet
)
111 line1
= u
"{u:>{uw}}:".format(
115 line2
= u
"{c:>{cw}}".format(
127 if iot
and media_url
:
129 response
= requests
.get(mu
)
130 image_to_display(StringIO(response
.content
))
133 def print_message(m
):
137 sender_screen_name
= '@' + m
['sender_screen_name']
138 sender_name
= m
['sender']['name']
140 recipient_screen_name
= '@' + m
['recipient_screen_name']
141 recipient_name
= m
['recipient']['name']
143 date
= parser
.parse(m
['created_at'])
144 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
145 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
148 res
= db
.message_to_rainbow_query(mid
)
150 db
.message_store(mid
)
151 res
= db
.message_to_rainbow_query(mid
)
152 rid
= res
[0].rainbow_id
155 sender
= cycle_color(sender_name
) + color_func(c
['MESSAGE']['sender'])(' ' + sender_screen_name
+ ' ')
156 recipient
= cycle_color(recipient_name
) + color_func(c
['MESSAGE']['recipient'])(' ' + recipient_screen_name
+ ' ')
157 user
= sender
+ color_func(c
['MESSAGE']['to'])(' >>> ') + recipient
158 meta
= color_func(c
['MESSAGE']['clock'])('[' + clock
+ ']') + color_func(c
['MESSAGE']['id'])(' [message_id=' + str(rid
) + '] ')
159 text
= ''.join(map(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
161 line1
= u
"{u:>{uw}}:".format(
165 line2
= u
"{c:>{cw}}".format(
178 def show_profile(u
, iot
=False):
184 screen_name
= u
['screen_name']
185 description
= u
['description']
186 profile_image_url
= u
['profile_image_url']
187 location
= u
['location']
189 created_at
= u
['created_at']
190 statuses_count
= u
['statuses_count']
191 friends_count
= u
['friends_count']
192 followers_count
= u
['followers_count']
195 statuses_count
= color_func(c
['PROFILE']['statuses_count'])(str(statuses_count
) + ' tweets')
196 friends_count
= color_func(c
['PROFILE']['friends_count'])(str(friends_count
) + ' following')
197 followers_count
= color_func(c
['PROFILE']['followers_count'])(str(followers_count
) + ' followers')
198 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
199 user
= cycle_color(name
) + color_func(c
['PROFILE']['nick'])(' @' + screen_name
+ ' : ') + count
200 profile_image_raw_url
= 'Profile photo: ' + color_func(c
['PROFILE']['profile_image_url'])(profile_image_url
)
201 description
= ''.join(
202 map(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
203 description
= color_func(c
['PROFILE']['description'])(description
)
204 location
= 'Location : ' + color_func(c
['PROFILE']['location'])(location
)
205 url
= 'URL : ' + (color_func(c
['PROFILE']['url'])(url
) if url
else '')
206 date
= parser
.parse(created_at
)
207 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
208 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
209 clock
= 'Join at ' + color_func(c
['PROFILE']['clock'])(clock
)
212 line1
= u
"{u:>{uw}}".format(
216 line2
= u
"{p:>{pw}}".format(
217 p
=profile_image_raw_url
,
218 pw
=len(profile_image_raw_url
) + 4,
220 line3
= u
"{d:>{dw}}".format(
222 dw
=len(description
) + 4,
224 line4
= u
"{l:>{lw}}".format(
226 lw
=len(location
) + 4,
228 line5
= u
"{u:>{uw}}".format(
232 line6
= u
"{c:>{cw}}".format(
241 response
= requests
.get(profile_image_url
)
242 image_to_display(StringIO(response
.content
), 2, 20)
245 for line
in [line3
, line4
, line5
, line6
]:
250 def print_trends(trends
):
254 for topic
in trends
[:c
['TREND_MAX']]:
257 line
= cycle_color(name
) + ': ' + color_func(TREND
['url'])(url
)