8 from twitter
.util
import printNicely
9 from StringIO
import StringIO
10 from dateutil
import parser
11 from .c_image
import *
18 def draw(t
, iot
=False, keyword
=None, fil
=[], ig
=[]):
26 screen_name
= t
['user']['screen_name']
27 name
= t
['user']['name']
28 created_at
= t
['created_at']
29 favorited
= t
['favorited']
30 date
= parser
.parse(created_at
)
31 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
32 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
38 urls
= t
['entities']['urls']
40 expanded_url
.append(u
['expanded_url'])
49 media
= t
['entities']['media']
51 media_url
.append(m
['media_url'])
56 screen_name
= '@' + screen_name
57 if fil
and screen_name
not in fil
:
59 if ig
and screen_name
in ig
:
63 res
= db
.tweet_to_rainbow_query(tid
)
66 res
= db
.tweet_to_rainbow_query(tid
)
67 rid
= res
[0].rainbow_id
70 user
= cycle_color(name
) + TWEET
['nick'](' ' + screen_name
+ ' ')
71 meta
= TWEET
['clock']('[' + clock
+ '] ') + TWEET
['id']('[id=' + str(rid
) + '] ')
73 meta
= meta
+ TWEET
['favorite'](u
'\u2605')
77 for index
in range(len(expanded_url
)):
79 lambda x
: expanded_url
[index
] if x
== url
[index
] else x
,
82 tweet
= map(lambda x
: TWEET
['rt'](x
) if x
== 'RT' else x
, tweet
)
83 # Highlight screen_name
84 tweet
= map(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, tweet
)
86 tweet
= map(lambda x
: TWEET
['link'](x
) if x
[0:4] == 'http' else x
, tweet
)
87 # Highlight search keyword
90 lambda x
: TWEET
['keyword'](x
) if
91 ''.join(c
for c
in x
if c
.isalnum()).lower() == keyword
.lower()
96 tweet
= ' '.join(tweet
)
99 line1
= u
"{u:>{uw}}:".format(
103 line2
= u
"{c:>{cw}}".format(
115 if iot
and media_url
:
117 response
= requests
.get(mu
)
118 image_to_display(StringIO(response
.content
))
121 def print_message(m
):
125 sender_screen_name
= '@' + m
['sender_screen_name']
126 sender_name
= m
['sender']['name']
128 recipient_screen_name
= '@' + m
['recipient_screen_name']
129 recipient_name
= m
['recipient']['name']
131 date
= parser
.parse(m
['created_at'])
132 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
133 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
136 res
= db
.message_to_rainbow_query(mid
)
138 db
.message_store(mid
)
139 res
= db
.message_to_rainbow_query(mid
)
140 rid
= res
[0].rainbow_id
143 sender
= cycle_color(sender_name
) + MESSAGE
['sender'](' ' + sender_screen_name
+ ' ')
144 recipient
= cycle_color(
145 recipient_name
) + MESSAGE
['recipient'](' ' + recipient_screen_name
+ ' ')
146 user
= sender
+ MESSAGE
['to'](' >>> ') + recipient
147 meta
= MESSAGE
['clock']('[' + clock
+ ']' + MESSAGE
['id'](' [message_id=' + str(rid
) + '] ')
148 text
= ''.join(map(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
150 line1
= u
"{u:>{uw}}:".format(
154 line2
= u
"{c:>{cw}}".format(
167 def show_profile(u
, iot
=False):
173 screen_name
= u
['screen_name']
174 description
= u
['description']
175 profile_image_url
= u
['profile_image_url']
176 location
= u
['location']
178 created_at
= u
['created_at']
179 statuses_count
= u
['statuses_count']
180 friends_count
= u
['friends_count']
181 followers_count
= u
['followers_count']
184 statuses_count
= PROFILE
['statuses_count'](str(statuses_count
) + ' tweets')
185 friends_count
= PROFILE
['friends_count'](str(friends_count
) + ' following')
186 followers_count
= PROFILE
['followers_count'](str(followers_count
) + ' followers')
187 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
188 user
= cycle_color(name
) + PROFILE
['nick'](' @' + screen_name
+ ' : ') + count
189 profile_image_raw_url
= 'Profile photo: ' + PROFILE
['profile_image_url'](profile_image_url
)
190 description
= ''.join(
191 map(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
192 description
= PROFILE
['description'](description
)
193 location
= 'Location : ' + PROFILE
['location'](location
)
194 url
= 'URL : ' + (PROFILE
['url'](url
) if url
else '')
195 date
= parser
.parse(created_at
)
196 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
197 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
198 clock
= 'Join at ' + PROFILE
['clock'](clock
)
201 line1
= u
"{u:>{uw}}".format(
205 line2
= u
"{p:>{pw}}".format(
206 p
=profile_image_raw_url
,
207 pw
=len(profile_image_raw_url
) + 4,
209 line3
= u
"{d:>{dw}}".format(
211 dw
=len(description
) + 4,
213 line4
= u
"{l:>{lw}}".format(
215 lw
=len(location
) + 4,
217 line5
= u
"{u:>{uw}}".format(
221 line6
= u
"{c:>{cw}}".format(
230 response
= requests
.get(profile_image_url
)
231 image_to_display(StringIO(response
.content
), 2, 20)
234 for line
in [line3
, line4
, line5
, line6
]:
239 def print_trends(trends
):
243 for topic
in trends
[:TREND_MAX
]:
246 line
= cycle_color(name
) + ': ' + TREND
['url'](url
)