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('term_')
27 else term_color(int(i
[5:]))
28 for i
in c
['CYCLE_COLOR']]
29 return colors_shuffle
, itertools
.cycle(colors_shuffle
)
30 g
['colors_shuffle'], g
['cyc'] = init_cycle()
37 g
['colors_shuffle'], g
['cyc'] = init_cycle()
42 Print a string with ordered color with each character
44 c
= [g
['colors_shuffle'][i
% 7](s
[i
]) for i
in xrange(len(s
))]
45 return reduce(lambda x
, y
: x
+ y
, c
)
48 def random_rainbow(s
):
50 Print a string with random color with each character
52 c
= [random
.choice(g
['colors_shuffle'])(i
) for i
in s
]
53 return reduce(lambda x
, y
: x
+ y
, c
)
65 cache
[args
] = func(*args
)
73 Cycle the colors_shuffle
75 return next(g
['cyc'])(s
)
82 fi
= figlet_format(text
, font
='doom')
84 [next(g
['cyc'])(i
) for i
in fi
.split('\n')]
88 def show_calendar(month
, date
, rel
):
90 Show the calendar in rainbow mode
92 month
= random_rainbow(month
)
93 date
= ' '.join([cycle_color(i
) for i
in date
.split(' ')])
94 today
= str(int(os
.popen('date +\'%d\'').read().strip()))
100 ary
= map(lambda x
: color_func(c
['CAL']['today'])(x
)
102 else color_func(c
['CAL']['days'])(x
)
104 printNicely(' '.join(ary
))
109 Check current theme and update if necessary
111 exists
= db
.theme_query()
112 themes
= [t
.theme_name
for t
in exists
]
113 if c
['theme'] != themes
[0]:
114 c
['theme'] = themes
[0]
116 if c
['theme'] == 'custom':
117 config
= os
.environ
.get(
119 os
.environ
.get('USERPROFILE',
120 '')) + os
.sep
+ '.rainbow_config.json'
122 config
= os
.path
.dirname(__file__
) + '/colorset/'+c
['theme']+'.json'
124 data
= load_config(config
)
128 # Re-init color cycle
129 g
['cyc'] = init_cycle()
132 def color_func(func_name
):
134 Call color function base on name
136 pure
= func_name
.encode('utf8')
137 if pure
.startswith('term_') and pure
[5:].isdigit():
138 return term_color(int(pure
[5:]))
139 return globals()[pure
]
142 def draw(t
, iot
=False, keyword
=None, fil
=[], ig
=[]):
151 screen_name
= t
['user']['screen_name']
152 name
= t
['user']['name']
153 created_at
= t
['created_at']
154 favorited
= t
['favorited']
155 date
= parser
.parse(created_at
)
156 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
157 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
163 urls
= t
['entities']['urls']
165 expanded_url
.append(u
['expanded_url'])
174 media
= t
['entities']['media']
176 media_url
.append(m
['media_url'])
181 screen_name
= '@' + screen_name
182 if fil
and screen_name
not in fil
:
184 if ig
and screen_name
in ig
:
188 res
= db
.tweet_to_rainbow_query(tid
)
191 res
= db
.tweet_to_rainbow_query(tid
)
192 rid
= res
[0].rainbow_id
196 name
) + color_func(c
['TWEET']['nick'])(' ' + screen_name
+ ' ')
197 meta
= color_func(c
['TWEET']['clock'])(
198 '[' + clock
+ '] ') + color_func(c
['TWEET']['id'])('[id=' + str(rid
) + '] ')
200 meta
= meta
+ color_func(c
['TWEET']['favorited'])(u
'\u2605')
204 for index
in range(len(expanded_url
)):
206 lambda x
: expanded_url
[index
] if x
== url
[index
] else x
,
210 lambda x
: color_func(
211 c
['TWEET']['rt'])(x
) if x
== 'RT' else x
,
213 # Highlight screen_name
214 tweet
= map(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, tweet
)
217 lambda x
: color_func(
218 c
['TWEET']['link'])(x
) if x
[
219 0:4] == 'http' else x
,
221 # Highlight search keyword
224 lambda x
: color_func(c
['TWEET']['keyword'])(x
) if
225 ''.join(c
for c
in x
if c
.isalnum()).lower() == keyword
.lower()
230 tweet
= ' '.join(tweet
)
233 line1
= u
"{u:>{uw}}:".format(
237 line2
= u
"{c:>{cw}}".format(
249 if iot
and media_url
:
251 response
= requests
.get(mu
)
252 image_to_display(StringIO(response
.content
))
255 def print_message(m
):
259 sender_screen_name
= '@' + m
['sender_screen_name']
260 sender_name
= m
['sender']['name']
262 recipient_screen_name
= '@' + m
['recipient_screen_name']
263 recipient_name
= m
['recipient']['name']
265 date
= parser
.parse(m
['created_at'])
266 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
267 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
270 res
= db
.message_to_rainbow_query(mid
)
272 db
.message_store(mid
)
273 res
= db
.message_to_rainbow_query(mid
)
274 rid
= res
[0].rainbow_id
277 sender
= cycle_color(
278 sender_name
) + color_func(c
['MESSAGE']['sender'])(' ' + sender_screen_name
+ ' ')
279 recipient
= cycle_color(recipient_name
) + color_func(
280 c
['MESSAGE']['recipient'])(
281 ' ' + recipient_screen_name
+ ' ')
282 user
= sender
+ color_func(c
['MESSAGE']['to'])(' >>> ') + recipient
284 c
['MESSAGE']['clock'])(
285 '[' + clock
+ ']') + color_func(
287 ' [message_id=' + str(rid
) + '] ')
288 text
= ''.join(map(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
290 line1
= u
"{u:>{uw}}:".format(
294 line2
= u
"{c:>{cw}}".format(
307 def show_profile(u
, iot
=False):
313 screen_name
= u
['screen_name']
314 description
= u
['description']
315 profile_image_url
= u
['profile_image_url']
316 location
= u
['location']
318 created_at
= u
['created_at']
319 statuses_count
= u
['statuses_count']
320 friends_count
= u
['friends_count']
321 followers_count
= u
['followers_count']
324 statuses_count
= color_func(
325 c
['PROFILE']['statuses_count'])(
326 str(statuses_count
) +
328 friends_count
= color_func(
329 c
['PROFILE']['friends_count'])(
332 followers_count
= color_func(
333 c
['PROFILE']['followers_count'])(
334 str(followers_count
) +
336 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
338 name
) + color_func(c
['PROFILE']['nick'])(' @' + screen_name
+ ' : ') + count
339 profile_image_raw_url
= 'Profile photo: ' + \
340 color_func(c
['PROFILE']['profile_image_url'])(profile_image_url
)
341 description
= ''.join(
342 map(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
343 description
= color_func(c
['PROFILE']['description'])(description
)
344 location
= 'Location : ' + color_func(c
['PROFILE']['location'])(location
)
345 url
= 'URL : ' + (color_func(c
['PROFILE']['url'])(url
) if url
else '')
346 date
= parser
.parse(created_at
)
347 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
348 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
349 clock
= 'Join at ' + color_func(c
['PROFILE']['clock'])(clock
)
352 line1
= u
"{u:>{uw}}".format(
356 line2
= u
"{p:>{pw}}".format(
357 p
=profile_image_raw_url
,
358 pw
=len(profile_image_raw_url
) + 4,
360 line3
= u
"{d:>{dw}}".format(
362 dw
=len(description
) + 4,
364 line4
= u
"{l:>{lw}}".format(
366 lw
=len(location
) + 4,
368 line5
= u
"{u:>{uw}}".format(
372 line6
= u
"{c:>{cw}}".format(
381 response
= requests
.get(profile_image_url
)
382 image_to_display(StringIO(response
.content
), 2, 20)
385 for line
in [line3
, line4
, line5
, line6
]:
390 def print_trends(trends
):
394 for topic
in trends
[:c
['TREND_MAX']]:
397 line
= cycle_color(name
) + ': ' + color_func(c
['TREND']['url'])(url
)