f23e4cacd70d8ab9558573289590a924673e3a8e
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 *
32 colors_shuffle
= [globals()[i
.encode('utf8')]
33 if not str(i
).isdigit()
34 else term_color(int(i
))
35 for i
in c
['CYCLE_COLOR']]
36 return itertools
.cycle(colors_shuffle
)
43 g
['cyc'] = init_cycle()
49 Print a string with ordered color with each character
51 colors_shuffle
= [globals()[i
.encode('utf8')]
52 if not str(i
).isdigit()
53 else term_color(int(i
))
54 for i
in c
['CYCLE_COLOR']]
55 colored
= [colors_shuffle
[i
% 7](s
[i
]) for i
in xrange(len(s
))]
56 return ''.join(colored
)
59 def random_rainbow(s
):
61 Print a string with random color with each character
63 colors_shuffle
= [globals()[i
.encode('utf8')]
64 if not str(i
).isdigit()
65 else term_color(int(i
))
66 for i
in c
['CYCLE_COLOR']]
67 colored
= [random
.choice(colors_shuffle
)(i
) for i
in s
]
68 return ''.join(colored
)
77 if args
not in g
['cache']:
78 g
['cache'][args
] = func(*args
)
79 return g
['cache'][args
]
86 Cycle the colors_shuffle
88 return next(g
['cyc'])(s
)
95 fi
= figlet_format(text
, font
='doom')
97 [next(g
['cyc'])(i
) for i
in fi
.split('\n')]
101 def show_calendar(month
, date
, rel
):
103 Show the calendar in rainbow mode
105 month
= random_rainbow(month
)
106 date
= ' '.join([cycle_color(i
) for i
in date
.split(' ')])
107 today
= str(int(os
.popen('date +\'%d\'').read().strip()))
112 ary
= line
.split(' ')
113 ary
= lmap(lambda x
: color_func(c
['CAL']['today'])(x
)
115 else color_func(c
['CAL']['days'])(x
), ary
)
116 printNicely(' '.join(ary
))
121 Check current theme and update if necessary
123 exists
= db
.theme_query()
124 themes
= [t
.theme_name
for t
in exists
]
125 if c
['THEME'] != themes
[0]:
126 c
['THEME'] = themes
[0]
127 config
= os
.path
.dirname(
128 __file__
) + '/colorset/' + c
['THEME'] + '.json'
130 data
= load_config(config
)
134 # Re-init color cycle
135 g
['cyc'] = init_cycle()
138 def color_func(func_name
):
140 Call color function base on name
142 if str(func_name
).isdigit():
143 return term_color(int(func_name
))
144 return globals()[func_name
]
147 def draw(t
, iot
=False, keyword
=None, check_semaphore
=False, fil
=[], ig
=[]):
156 screen_name
= t
['user']['screen_name']
157 name
= t
['user']['name']
158 created_at
= t
['created_at']
159 favorited
= t
['favorited']
160 date
= parser
.parse(created_at
)
161 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
162 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
164 # Pull extended retweet text
166 text
= 'RT @{0}: {1}'.format(t
['retweeted_status']['user']['screen_name'],
167 t
['retweeted_status']['text'])
171 text
= unescape(text
)
177 urls
= t
['entities']['urls']
179 expanded_url
.append(u
['expanded_url'])
188 media
= t
['entities']['media']
190 media_url
.append(m
['media_url'])
195 screen_name
= '@' + screen_name
196 if fil
and screen_name
not in fil
:
198 if ig
and screen_name
in ig
:
202 res
= db
.tweet_to_rainbow_query(tid
)
205 res
= db
.tweet_to_rainbow_query(tid
)
206 rid
= res
[0].rainbow_id
210 name
) + color_func(c
['TWEET']['nick'])(' ' + screen_name
+ ' ')
211 meta
= color_func(c
['TWEET']['clock'])(
212 '[' + clock
+ '] ') + color_func(c
['TWEET']['id'])('[id=' + str(rid
) + '] ')
214 meta
= meta
+ color_func(c
['TWEET']['favorited'])(u
'\u2605')
218 for index
in range(len(expanded_url
)):
220 lambda x
: expanded_url
[index
] if x
== url
[index
] else x
,
224 lambda x
: color_func(
225 c
['TWEET']['rt'])(x
) if x
== 'RT' else x
,
227 # Highlight screen_name
228 tweet
= lmap(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, tweet
)
231 lambda x
: color_func(
232 c
['TWEET']['link'])(x
) if x
[
233 0:4] == 'http' else x
,
237 tweet
= ' '.join(tweet
)
239 roj
= re
.search(keyword
,tweet
,re
.IGNORECASE
)
242 ary
= tweet
.split(occur
)
243 delimeter
= color_func(c
['TWEET']['keyword'])(occur
)
244 tweet
= delimeter
.join(ary
)
247 line1
= u
"{u:>{uw}}:".format(
251 line2
= u
"{c:>{cw}}".format(
257 # Check the semaphore lock
259 while db
.semaphore_query():
269 if iot
and media_url
:
272 response
= requests
.get(mu
)
273 image_to_display(BytesIO(response
.content
))
275 printNicely(red('Sorry, image link is broken'))
278 def print_message(m
):
282 sender_screen_name
= '@' + m
['sender_screen_name']
283 sender_name
= m
['sender']['name']
284 text
= unescape(m
['text'])
285 recipient_screen_name
= '@' + m
['recipient_screen_name']
286 recipient_name
= m
['recipient']['name']
288 date
= parser
.parse(m
['created_at'])
289 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
290 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
293 res
= db
.message_to_rainbow_query(mid
)
295 db
.message_store(mid
)
296 res
= db
.message_to_rainbow_query(mid
)
297 rid
= res
[0].rainbow_id
300 sender
= cycle_color(
301 sender_name
) + color_func(c
['MESSAGE']['sender'])(' ' + sender_screen_name
+ ' ')
302 recipient
= cycle_color(recipient_name
) + color_func(
303 c
['MESSAGE']['recipient'])(
304 ' ' + recipient_screen_name
+ ' ')
305 user
= sender
+ color_func(c
['MESSAGE']['to'])(' >>> ') + recipient
307 c
['MESSAGE']['clock'])(
308 '[' + clock
+ ']') + color_func(
310 ' [message_id=' + str(rid
) + '] ')
311 text
= ''.join(lmap(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
313 line1
= u
"{u:>{uw}}:".format(
317 line2
= u
"{c:>{cw}}".format(
330 def show_profile(u
, iot
=False):
336 screen_name
= u
['screen_name']
337 description
= u
['description']
338 profile_image_url
= u
['profile_image_url']
339 location
= u
['location']
341 created_at
= u
['created_at']
342 statuses_count
= u
['statuses_count']
343 friends_count
= u
['friends_count']
344 followers_count
= u
['followers_count']
347 statuses_count
= color_func(
348 c
['PROFILE']['statuses_count'])(
349 str(statuses_count
) +
351 friends_count
= color_func(
352 c
['PROFILE']['friends_count'])(
355 followers_count
= color_func(
356 c
['PROFILE']['followers_count'])(
357 str(followers_count
) +
359 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
361 name
) + color_func(c
['PROFILE']['nick'])(' @' + screen_name
+ ' : ') + count
362 profile_image_raw_url
= 'Profile photo: ' + \
363 color_func(c
['PROFILE']['profile_image_url'])(profile_image_url
)
364 description
= ''.join(
365 lmap(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
366 description
= color_func(c
['PROFILE']['description'])(description
)
367 location
= 'Location : ' + color_func(c
['PROFILE']['location'])(location
)
368 url
= 'URL : ' + (color_func(c
['PROFILE']['url'])(url
) if url
else '')
369 date
= parser
.parse(created_at
)
370 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
371 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
372 clock
= 'Join at ' + color_func(c
['PROFILE']['clock'])(clock
)
375 line1
= u
"{u:>{uw}}".format(
379 line2
= u
"{p:>{pw}}".format(
380 p
=profile_image_raw_url
,
381 pw
=len(profile_image_raw_url
) + 4,
383 line3
= u
"{d:>{dw}}".format(
385 dw
=len(description
) + 4,
387 line4
= u
"{l:>{lw}}".format(
389 lw
=len(location
) + 4,
391 line5
= u
"{u:>{uw}}".format(
395 line6
= u
"{c:>{cw}}".format(
405 response
= requests
.get(profile_image_url
)
406 image_to_display(BytesIO(response
.content
), 2, 20)
411 for line
in [line3
, line4
, line5
, line6
]:
416 def print_trends(trends
):
420 for topic
in trends
[:c
['TREND_MAX']]:
423 line
= cycle_color(name
) + ': ' + color_func(c
['TREND']['url'])(url
)
428 def print_list(group
):
434 name
= g
['full_name']
435 name
= color_func(c
['GROUP']['name'])(name
+ ' : ')
436 member
= str(g
['member_count'])
437 member
= color_func(c
['GROUP']['member'])(member
+ ' member')
438 subscriber
= str(g
['subscriber_count'])
439 subscriber
= color_func(
440 c
['GROUP']['subscriber'])(
443 description
= g
['description'].strip()
444 description
= color_func(c
['GROUP']['description'])(description
)
446 mode
= color_func(c
['GROUP']['mode'])('Type: ' + mode
)
447 created_at
= g
['created_at']
448 date
= parser
.parse(created_at
)
449 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
450 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
451 clock
= 'Created at ' + color_func(c
['GROUP']['clock'])(clock
)
454 line1
= ' ' * 2 + name
+ member
+ ' ' + subscriber
455 line2
= ' ' * 4 + description
456 line3
= ' ' * 4 + mode
457 line4
= ' ' * 4 + clock
469 # Start the color cycle