29240ded4307e768e7db021358c8d63225d790df
8 from twitter
.util
import printNicely
9 from functools
import wraps
10 from pyfiglet
import figlet_format
11 from dateutil
import parser
12 from .c_image
import *
16 from .py3patch
import *
27 colors_shuffle
= [globals()[i
.encode('utf8')]
28 if not str(i
).isdigit()
29 else term_color(int(i
))
30 for i
in c
['CYCLE_COLOR']]
31 return itertools
.cycle(colors_shuffle
)
38 g
['cyc'] = init_cycle()
44 Print a string with ordered color with each character
46 colors_shuffle
= [globals()[i
.encode('utf8')]
47 if not str(i
).isdigit()
48 else term_color(int(i
))
49 for i
in c
['CYCLE_COLOR']]
50 colored
= [colors_shuffle
[i
% 7](s
[i
]) for i
in xrange(len(s
))]
51 return ''.join(colored
)
54 def random_rainbow(s
):
56 Print a string with random color with each character
58 colors_shuffle
= [globals()[i
.encode('utf8')]
59 if not str(i
).isdigit()
60 else term_color(int(i
))
61 for i
in c
['CYCLE_COLOR']]
62 colored
= [random
.choice(colors_shuffle
)(i
) for i
in s
]
63 return ''.join(colored
)
72 if args
not in g
['cache']:
73 g
['cache'][args
] = func(*args
)
74 return g
['cache'][args
]
81 Cycle the colors_shuffle
83 return next(g
['cyc'])(s
)
90 fi
= figlet_format(text
, font
='doom')
92 [next(g
['cyc'])(i
) for i
in fi
.split('\n')]
96 def show_calendar(month
, date
, rel
):
98 Show the calendar in rainbow mode
100 month
= random_rainbow(month
)
101 date
= ' '.join([cycle_color(i
) for i
in date
.split(' ')])
102 today
= str(int(os
.popen('date +\'%d\'').read().strip()))
107 ary
= line
.split(' ')
108 ary
= lmap(lambda x
: color_func(c
['CAL']['today'])(x
)
110 else color_func(c
['CAL']['days'])(x
), ary
)
111 printNicely(' '.join(ary
))
116 Check if config is changed
119 data
= get_all_config()
122 if data
[key
] != c
[key
]:
130 Check current theme and update if necessary
132 exists
= db
.theme_query()
133 themes
= [t
.theme_name
for t
in exists
]
134 if c
['THEME'] != themes
[0]:
135 c
['THEME'] = themes
[0]
136 config
= os
.path
.dirname(
137 __file__
) + '/colorset/' + c
['THEME'] + '.json'
139 data
= load_config(config
)
143 # Re-init color cycle
144 g
['cyc'] = init_cycle()
147 def color_func(func_name
):
149 Call color function base on name
151 if str(func_name
).isdigit():
152 return term_color(int(func_name
))
153 return globals()[func_name
]
156 def draw(t
, keyword
=None, check_semaphore
=False, fil
=[], ig
=[]):
166 screen_name
= t
['user']['screen_name']
167 name
= t
['user']['name']
168 created_at
= t
['created_at']
169 favorited
= t
['favorited']
170 date
= parser
.parse(created_at
)
171 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
172 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
174 # Pull extended retweet text
176 text
= 'RT @' + t
['retweeted_status']['user']['screen_name'] + ': ' +\
177 t
['retweeted_status']['text']
181 # Unescape HTML character
182 text
= unescape(text
)
188 urls
= t
['entities']['urls']
190 expanded_url
.append(u
['expanded_url'])
199 media
= t
['entities']['media']
201 media_url
.append(m
['media_url'])
206 screen_name
= '@' + screen_name
207 if fil
and screen_name
not in fil
:
209 if ig
and screen_name
in ig
:
213 res
= db
.tweet_to_rainbow_query(tid
)
216 res
= db
.tweet_to_rainbow_query(tid
)
217 rid
= res
[0].rainbow_id
221 name
) + color_func(c
['TWEET']['nick'])(' ' + screen_name
+ ' ')
222 meta
= color_func(c
['TWEET']['clock'])(
223 '[' + clock
+ '] ') + color_func(c
['TWEET']['id'])('[id=' + str(rid
) + '] ')
225 meta
= meta
+ color_func(c
['TWEET']['favorited'])(u
'\u2605')
229 for index
in range(len(expanded_url
)):
231 lambda x
: expanded_url
[index
] if x
== url
[index
] else x
,
235 lambda x
: color_func(
236 c
['TWEET']['rt'])(x
) if x
== 'RT' else x
,
238 # Highlight screen_name
239 tweet
= lmap(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, tweet
)
242 lambda x
: color_func(
243 c
['TWEET']['link'])(x
) if x
[
244 0:4] == 'http' else x
,
248 tweet
= ' '.join(tweet
)
250 roj
= re
.search(keyword
, tweet
, re
.IGNORECASE
)
253 ary
= tweet
.split(occur
)
254 delimeter
= color_func(c
['TWEET']['keyword'])(occur
)
255 tweet
= delimeter
.join(ary
)
258 line1
= u
"{u:>{uw}}:".format(
262 line2
= u
"{c:>{cw}}".format(
268 # Check the semaphore lock
270 while db
.semaphore_query():
280 if c
['IMAGE_ON_TERM'] and media_url
:
283 response
= requests
.get(mu
)
284 image_to_display(BytesIO(response
.content
))
286 printNicely(red('Sorry, image link is broken'))
289 def print_message(m
):
293 sender_screen_name
= '@' + m
['sender_screen_name']
294 sender_name
= m
['sender']['name']
295 text
= unescape(m
['text'])
296 recipient_screen_name
= '@' + m
['recipient_screen_name']
297 recipient_name
= m
['recipient']['name']
299 date
= parser
.parse(m
['created_at'])
300 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
301 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
304 res
= db
.message_to_rainbow_query(mid
)
306 db
.message_store(mid
)
307 res
= db
.message_to_rainbow_query(mid
)
308 rid
= res
[0].rainbow_id
311 sender
= cycle_color(
312 sender_name
) + color_func(c
['MESSAGE']['sender'])(' ' + sender_screen_name
+ ' ')
313 recipient
= cycle_color(recipient_name
) + color_func(
314 c
['MESSAGE']['recipient'])(
315 ' ' + recipient_screen_name
+ ' ')
316 user
= sender
+ color_func(c
['MESSAGE']['to'])(' >>> ') + recipient
318 c
['MESSAGE']['clock'])(
319 '[' + clock
+ ']') + color_func(
321 ' [message_id=' + str(rid
) + '] ')
322 text
= ''.join(lmap(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
324 line1
= u
"{u:>{uw}}:".format(
328 line2
= u
"{c:>{cw}}".format(
347 screen_name
= u
['screen_name']
348 description
= u
['description']
349 profile_image_url
= u
['profile_image_url']
350 location
= u
['location']
352 created_at
= u
['created_at']
353 statuses_count
= u
['statuses_count']
354 friends_count
= u
['friends_count']
355 followers_count
= u
['followers_count']
358 statuses_count
= color_func(
359 c
['PROFILE']['statuses_count'])(
360 str(statuses_count
) +
362 friends_count
= color_func(
363 c
['PROFILE']['friends_count'])(
366 followers_count
= color_func(
367 c
['PROFILE']['followers_count'])(
368 str(followers_count
) +
370 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
372 name
) + color_func(c
['PROFILE']['nick'])(' @' + screen_name
+ ' : ') + count
373 profile_image_raw_url
= 'Profile photo: ' + \
374 color_func(c
['PROFILE']['profile_image_url'])(profile_image_url
)
375 description
= ''.join(
376 lmap(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
377 description
= color_func(c
['PROFILE']['description'])(description
)
378 location
= 'Location : ' + color_func(c
['PROFILE']['location'])(location
)
379 url
= 'URL : ' + (color_func(c
['PROFILE']['url'])(url
) if url
else '')
380 date
= parser
.parse(created_at
)
381 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
382 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
383 clock
= 'Join at ' + color_func(c
['PROFILE']['clock'])(clock
)
386 line1
= u
"{u:>{uw}}".format(
390 line2
= u
"{p:>{pw}}".format(
391 p
=profile_image_raw_url
,
392 pw
=len(profile_image_raw_url
) + 4,
394 line3
= u
"{d:>{dw}}".format(
396 dw
=len(description
) + 4,
398 line4
= u
"{l:>{lw}}".format(
400 lw
=len(location
) + 4,
402 line5
= u
"{u:>{uw}}".format(
406 line6
= u
"{c:>{cw}}".format(
414 if c
['IMAGE_ON_TERM']:
416 response
= requests
.get(profile_image_url
)
417 image_to_display(BytesIO(response
.content
), 2, 20)
422 for line
in [line3
, line4
, line5
, line6
]:
427 def print_trends(trends
):
431 for topic
in trends
[:c
['TREND_MAX']]:
434 line
= cycle_color(name
) + ': ' + color_func(c
['TREND']['url'])(url
)
439 def print_list(group
):
445 name
= g
['full_name']
446 name
= color_func(c
['GROUP']['name'])(name
+ ' : ')
447 member
= str(g
['member_count'])
448 member
= color_func(c
['GROUP']['member'])(member
+ ' member')
449 subscriber
= str(g
['subscriber_count'])
450 subscriber
= color_func(
451 c
['GROUP']['subscriber'])(
454 description
= g
['description'].strip()
455 description
= color_func(c
['GROUP']['description'])(description
)
457 mode
= color_func(c
['GROUP']['mode'])('Type: ' + mode
)
458 created_at
= g
['created_at']
459 date
= parser
.parse(created_at
)
460 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
461 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
462 clock
= 'Created at ' + color_func(c
['GROUP']['clock'])(clock
)
465 line1
= ' ' * 2 + name
+ member
+ ' ' + subscriber
466 line2
= ' ' * 4 + description
467 line3
= ' ' * 4 + mode
468 line4
= ' ' * 4 + clock
480 # Start the color cycle