c2119ff779e03cf0ca77631991ddccf81398f0f2
7 from twitter
.util
import printNicely
8 from functools
import wraps
9 from pyfiglet
import figlet_format
10 from functools
import reduce
11 from StringIO
import StringIO
12 from dateutil
import parser
13 from .c_image
import *
25 colors_shuffle
= [globals()[i
.encode('utf8')]
26 if not i
.startswith('RGB_')
28 for i
in c
['CYCLE_COLOR']]
29 return itertools
.cycle(colors_shuffle
)
34 Print a string with ordered color with each character
36 c
= [colors_shuffle
[i
% 7](s
[i
]) for i
in xrange(len(s
))]
37 return reduce(lambda x
, y
: x
+ y
, c
)
40 def random_rainbow(s
):
42 Print a string with random color with each character
44 c
= [random
.choice(colors_shuffle
)(i
) for i
in s
]
45 return reduce(lambda x
, y
: x
+ y
, c
)
57 cache
[args
] = func(*args
)
65 Cycle the colors_shuffle
74 fi
= figlet_format(text
, font
='doom')
76 [next(cyc
)(i
) for i
in fi
.split('\n')]
82 Check current theme and update if necessary
84 exists
= db
.theme_query()
85 themes
= [t
.theme_name
for t
in exists
]
86 if c
['theme'] != themes
[0]:
87 c
['theme'] = themes
[0]
89 if c
['theme'] == 'custom':
90 config
= os
.environ
.get(
92 os
.environ
.get('USERPROFILE',
93 '')) + os
.sep
+ '.rainbow_config.json'
95 config
= 'rainbowstream/colorset/'+c
['theme']+'.json'
97 data
= load_config(config
)
101 # Re-init color cycle
105 def color_func(func_name
):
107 Call color function base on name
109 pure
= func_name
.encode('utf8')
110 if pure
.startswith('RGB_') and pure
[4:].isdigit():
111 return RGB(int(pure
[4:]))
112 return globals()[pure
]
115 def draw(t
, iot
=False, keyword
=None, fil
=[], ig
=[]):
124 screen_name
= t
['user']['screen_name']
125 name
= t
['user']['name']
126 created_at
= t
['created_at']
127 favorited
= t
['favorited']
128 date
= parser
.parse(created_at
)
129 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
130 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
136 urls
= t
['entities']['urls']
138 expanded_url
.append(u
['expanded_url'])
147 media
= t
['entities']['media']
149 media_url
.append(m
['media_url'])
154 screen_name
= '@' + screen_name
155 if fil
and screen_name
not in fil
:
157 if ig
and screen_name
in ig
:
161 res
= db
.tweet_to_rainbow_query(tid
)
164 res
= db
.tweet_to_rainbow_query(tid
)
165 rid
= res
[0].rainbow_id
169 name
) + color_func(c
['TWEET']['nick'])(' ' + screen_name
+ ' ')
170 meta
= color_func(c
['TWEET']['clock'])(
171 '[' + clock
+ '] ') + color_func(c
['TWEET']['id'])('[id=' + str(rid
) + '] ')
173 meta
= meta
+ color_func(c
['TWEET']['favorite'])(u
'\u2605')
177 for index
in range(len(expanded_url
)):
179 lambda x
: expanded_url
[index
] if x
== url
[index
] else x
,
183 lambda x
: color_func(
184 c
['TWEET']['rt'])(x
) if x
== 'RT' else x
,
186 # Highlight screen_name
187 tweet
= map(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, tweet
)
190 lambda x
: color_func(
191 c
['TWEET']['link'])(x
) if x
[
192 0:4] == 'http' else x
,
194 # Highlight search keyword
197 lambda x
: color_func(c
['TWEET']['keyword'])(x
) if
198 ''.join(c
for c
in x
if c
.isalnum()).lower() == keyword
.lower()
203 tweet
= ' '.join(tweet
)
206 line1
= u
"{u:>{uw}}:".format(
210 line2
= u
"{c:>{cw}}".format(
222 if iot
and media_url
:
224 response
= requests
.get(mu
)
225 image_to_display(StringIO(response
.content
))
228 def print_message(m
):
232 sender_screen_name
= '@' + m
['sender_screen_name']
233 sender_name
= m
['sender']['name']
235 recipient_screen_name
= '@' + m
['recipient_screen_name']
236 recipient_name
= m
['recipient']['name']
238 date
= parser
.parse(m
['created_at'])
239 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
240 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
243 res
= db
.message_to_rainbow_query(mid
)
245 db
.message_store(mid
)
246 res
= db
.message_to_rainbow_query(mid
)
247 rid
= res
[0].rainbow_id
250 sender
= cycle_color(
251 sender_name
) + color_func(c
['MESSAGE']['sender'])(' ' + sender_screen_name
+ ' ')
252 recipient
= cycle_color(recipient_name
) + color_func(
253 c
['MESSAGE']['recipient'])(
254 ' ' + recipient_screen_name
+ ' ')
255 user
= sender
+ color_func(c
['MESSAGE']['to'])(' >>> ') + recipient
257 c
['MESSAGE']['clock'])(
258 '[' + clock
+ ']') + color_func(
260 ' [message_id=' + str(rid
) + '] ')
261 text
= ''.join(map(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
263 line1
= u
"{u:>{uw}}:".format(
267 line2
= u
"{c:>{cw}}".format(
280 def show_profile(u
, iot
=False):
286 screen_name
= u
['screen_name']
287 description
= u
['description']
288 profile_image_url
= u
['profile_image_url']
289 location
= u
['location']
291 created_at
= u
['created_at']
292 statuses_count
= u
['statuses_count']
293 friends_count
= u
['friends_count']
294 followers_count
= u
['followers_count']
297 statuses_count
= color_func(
298 c
['PROFILE']['statuses_count'])(
299 str(statuses_count
) +
301 friends_count
= color_func(
302 c
['PROFILE']['friends_count'])(
305 followers_count
= color_func(
306 c
['PROFILE']['followers_count'])(
307 str(followers_count
) +
309 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
311 name
) + color_func(c
['PROFILE']['nick'])(' @' + screen_name
+ ' : ') + count
312 profile_image_raw_url
= 'Profile photo: ' + \
313 color_func(c
['PROFILE']['profile_image_url'])(profile_image_url
)
314 description
= ''.join(
315 map(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
316 description
= color_func(c
['PROFILE']['description'])(description
)
317 location
= 'Location : ' + color_func(c
['PROFILE']['location'])(location
)
318 url
= 'URL : ' + (color_func(c
['PROFILE']['url'])(url
) if url
else '')
319 date
= parser
.parse(created_at
)
320 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
321 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
322 clock
= 'Join at ' + color_func(c
['PROFILE']['clock'])(clock
)
325 line1
= u
"{u:>{uw}}".format(
329 line2
= u
"{p:>{pw}}".format(
330 p
=profile_image_raw_url
,
331 pw
=len(profile_image_raw_url
) + 4,
333 line3
= u
"{d:>{dw}}".format(
335 dw
=len(description
) + 4,
337 line4
= u
"{l:>{lw}}".format(
339 lw
=len(location
) + 4,
341 line5
= u
"{u:>{uw}}".format(
345 line6
= u
"{c:>{cw}}".format(
354 response
= requests
.get(profile_image_url
)
355 image_to_display(StringIO(response
.content
), 2, 20)
358 for line
in [line3
, line4
, line5
, line6
]:
363 def print_trends(trends
):
367 for topic
in trends
[:c
['TREND_MAX']]:
370 line
= cycle_color(name
) + ': ' + color_func(c
['TREND']['url'])(url
)