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
) + grey(' ' + screen_name
+ ' ')
71 meta
= grey('[' + clock
+ '] [id=' + str(rid
) + '] ')
73 meta
= meta
+ green(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
: grey(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
: cyan(x
) if x
[0:4] == 'http' else x
, tweet
)
87 # Highlight search keyword
90 lambda x
: on_yellow(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
142 sender
= cycle_color(sender_name
) + grey(' ' + sender_screen_name
+ ' ')
143 recipient
= cycle_color(
144 recipient_name
) + grey(' ' + recipient_screen_name
+ ' ')
145 user
= sender
+ magenta(' >>> ') + recipient
146 meta
= grey('[' + clock
+ '] [message_id=' + str(rid
) + '] ')
147 text
= ''.join(map(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
149 line1
= u
"{u:>{uw}}:".format(
153 line2
= u
"{c:>{cw}}".format(
166 def show_profile(u
, iot
=False):
172 screen_name
= u
['screen_name']
173 description
= u
['description']
174 profile_image_url
= u
['profile_image_url']
175 location
= u
['location']
177 created_at
= u
['created_at']
178 statuses_count
= u
['statuses_count']
179 friends_count
= u
['friends_count']
180 followers_count
= u
['followers_count']
182 statuses_count
= green(str(statuses_count
) + ' tweets')
183 friends_count
= green(str(friends_count
) + ' following')
184 followers_count
= green(str(followers_count
) + ' followers')
185 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
186 user
= cycle_color(name
) + grey(' @' + screen_name
+ ' : ') + count
187 profile_image_raw_url
= 'Profile photo: ' + cyan(profile_image_url
)
188 description
= ''.join(
189 map(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
190 description
= yellow(description
)
191 location
= 'Location : ' + magenta(location
)
192 url
= 'URL : ' + (cyan(url
) if url
else '')
193 date
= parser
.parse(created_at
)
194 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
195 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
196 clock
= 'Join at ' + white(clock
)
198 line1
= u
"{u:>{uw}}".format(
202 line2
= u
"{p:>{pw}}".format(
203 p
=profile_image_raw_url
,
204 pw
=len(profile_image_raw_url
) + 4,
206 line3
= u
"{d:>{dw}}".format(
208 dw
=len(description
) + 4,
210 line4
= u
"{l:>{lw}}".format(
212 lw
=len(location
) + 4,
214 line5
= u
"{u:>{uw}}".format(
218 line6
= u
"{c:>{cw}}".format(
226 response
= requests
.get(profile_image_url
)
227 image_to_display(StringIO(response
.content
), 2, 20)
230 for line
in [line3
, line4
, line5
, line6
]:
235 def print_trends(trends
):
239 for topic
in trends
[:TREND_MAX
]:
242 line
= cycle_color(name
) + ': ' + cyan(url
)