10 from twitter
.util
import printNicely
11 from functools
import wraps
12 from pyfiglet
import figlet_format
13 from dateutil
import parser
14 from .c_image
import *
17 from .py3patch
import *
19 # Draw global variables
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 dg
['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 dg
['cache']:
73 dg
['cache'][args
] = func(*args
)
74 return dg
['cache'][args
]
81 Cycle the colors_shuffle
83 return next(dg
['cyc'])(s
)
90 fi
= figlet_format(text
, font
='doom')
92 [next(dg
['cyc'])(i
) for i
in fi
.split('\n')]
98 Check if config is changed
101 data
= get_all_config()
104 if data
[key
] != c
[key
]:
110 def validate_theme(theme
):
112 Validate a theme exists or not
114 # Theme changed check
115 files
= os
.listdir(os
.path
.dirname(__file__
) + '/colorset')
116 themes
= [f
.split('.')[0] for f
in files
if f
.split('.')[-1] == 'json']
117 return theme
in themes
120 def reload_theme(value
, prev
):
122 Check current theme and update if necessary
125 config
= os
.path
.dirname(
126 __file__
) + '/colorset/' + value
+ '.json'
128 data
= load_config(config
)
132 # Restart color cycle and update config
134 set_config('THEME', value
)
139 def color_func(func_name
):
141 Call color function base on name
143 if str(func_name
).isdigit():
144 return term_color(int(func_name
))
145 return globals()[func_name
]
148 def draw(t
, keyword
=None, humanize
=True, noti
=False, fil
=[], ig
=[]):
158 screen_name
= t
['user']['screen_name']
159 name
= t
['user']['name']
160 created_at
= t
['created_at']
161 favorited
= t
['favorited']
162 retweet_count
= t
['retweet_count']
163 favorite_count
= t
['favorite_count']
164 date
= parser
.parse(created_at
)
165 date
= arrow
.get(date
).to('local')
167 lang
, encode
= locale
.getdefaultlocale()
168 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
171 clock_format
= c
['FORMAT']['TWEET']['CLOCK_FORMAT']
173 clock_format
= '%Y/%m/%d %H:%M:%S'
174 clock
= date
.datetime
.strftime(clock_format
)
176 # Pull extended retweet text
178 text
= 'RT @' + t
['retweeted_status']['user']['screen_name'] + ': ' +\
179 t
['retweeted_status']['text']
180 # Display as a notification
181 target
= t
['retweeted_status']['user']['screen_name']
182 if all([target
== c
['original_name'], not noti
]):
183 # Add to evens for 'notification' command
184 t
['event'] = 'retweet'
185 c
['events'].append(t
)
191 # Unescape HTML character
192 text
= unescape(text
)
198 urls
= t
['entities']['urls']
200 expanded_url
.append(u
['expanded_url'])
209 media
= t
['entities']['media']
211 media_url
.append(m
['media_url'])
216 mytweet
= screen_name
== c
['original_name']
217 screen_name
= '@' + screen_name
218 fil
= list(set((fil
or []) + c
['ONLY_LIST']))
219 ig
= list(set((ig
or []) + c
['IGNORE_LIST']))
220 if fil
and screen_name
not in fil
:
222 if ig
and screen_name
in ig
:
226 if tid
not in c
['tweet_dict']:
227 c
['tweet_dict'].append(tid
)
228 rid
= len(c
['tweet_dict']) - 1
230 rid
= c
['tweet_dict'].index(tid
)
233 name
= cycle_color(name
)
235 nick
= color_func(c
['TWEET']['mynick'])(screen_name
)
237 nick
= color_func(c
['TWEET']['nick'])(screen_name
)
242 fav
= color_func(c
['TWEET']['favorited'])(u
'\u2605')
247 for index
in xrange(len(expanded_url
)):
249 lambda x
: expanded_url
[index
]
255 lambda x
: color_func(c
['TWEET']['rt'])(x
)
259 # Highlight screen_name
260 tweet
= lmap(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, tweet
)
263 lambda x
: color_func(c
['TWEET']['link'])(x
)
264 if x
.startswith('http')
269 lambda x
: color_func(c
['TWEET']['hashtag'])(x
)
275 tweet
= [color_func(c
['TWEET']['mytweet'])(x
)
279 x
.startswith('http'),
283 tweet
= ' '.join(tweet
)
285 roj
= re
.search(keyword
, tweet
, re
.IGNORECASE
)
288 ary
= tweet
.split(occur
)
289 delimiter
= color_func(c
['TWEET']['keyword'])(occur
)
290 tweet
= delimiter
.join(ary
)
292 # Load config formater
295 formater
= c
['FORMAT']['TWEET']['DISPLAY']
296 formater
= name
.join(formater
.split('#name'))
297 formater
= nick
.join(formater
.split('#nick'))
298 formater
= fav
.join(formater
.split('#fav'))
299 formater
= tweet
.join(formater
.split('#tweet'))
301 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
302 delimiter
= color_func(c
['TWEET']['clock'])(
303 clock
.join(word
.split('#clock')))
304 formater
= delimiter
.join(formater
.split(word
))
306 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
307 delimiter
= color_func(c
['TWEET']['id'])(id.join(word
.split('#id')))
308 formater
= delimiter
.join(formater
.split(word
))
309 # Change retweet count word
310 word
= [wo
for wo
in formater
.split() if '#rt_count' in wo
][0]
311 delimiter
= color_func(c
['TWEET']['retweet_count'])(
312 str(retweet_count
).join(word
.split('#rt_count')))
313 formater
= delimiter
.join(formater
.split(word
))
314 # Change favorites count word
315 word
= [wo
for wo
in formater
.split() if '#fa_count' in wo
][0]
316 delimiter
= color_func(c
['TWEET']['favorite_count'])(
317 str(favorite_count
).join(word
.split('#fa_count')))
318 formater
= delimiter
.join(formater
.split(word
))
322 # Add spaces in begining of line if this is inside a notification
324 formater
= '\n '.join(formater
.split('\n'))
326 if formater
.startswith('\n'):
327 formater
= formater
[1:]
330 printNicely(formater
)
333 if c
['IMAGE_ON_TERM'] and media_url
:
336 response
= requests
.get(mu
)
337 image_to_display(BytesIO(response
.content
))
339 printNicely(red('Sorry, image link is broken'))
342 def print_threads(d
):
344 Print threads of messages
349 messages
= d
[partner
]
350 count
= len(messages
)
351 screen_name
= '@' + partner
[0]
353 screen_name
= color_func(c
['MESSAGE']['partner'])(screen_name
)
354 name
= cycle_color(name
)
355 thread_id
= color_func(c
['MESSAGE']['id'])('thread_id:' + str(id))
356 line
= ' ' * 2 + name
+ ' ' + screen_name
+ \
357 ' (' + str(count
) + ' message) ' + thread_id
365 def print_thread(partner
, me_nick
, me_name
):
367 Print a thread of messages
369 # Sort messages by time
370 messages
= dg
['thread'][partner
]
371 messages
.sort(key
=lambda x
: parser
.parse(x
['created_at']))
372 # Use legacy display on non-ascii text message
373 ms
= [m
['text'] for m
in messages
]
374 ums
= [m
for m
in ms
if not all(ord(c
) < 128 for c
in m
)]
380 # Print the first line
381 dg
['frame_margin'] = margin
= 2
382 partner_nick
= partner
[0]
383 partner_name
= partner
[1]
384 left_size
= len(partner_nick
) + len(partner_name
) + 2
385 right_size
= len(me_nick
) + len(me_name
) + 2
386 partner_nick
= color_func(c
['MESSAGE']['partner'])('@' + partner_nick
)
387 partner_name
= cycle_color(partner_name
)
388 me_screen_name
= color_func(c
['MESSAGE']['me'])('@' + me_nick
)
389 me_name
= cycle_color(me_name
)
390 left
= ' ' * margin
+ partner_name
+ ' ' + partner_nick
391 right
= me_name
+ ' ' + me_screen_name
+ ' ' * margin
392 h
, w
= os
.popen('stty size', 'r').read().split()
394 line
= '{}{}{}'.format(
395 left
, ' ' * (w
- left_size
- right_size
- 2 * margin
), right
)
401 if m
['sender_screen_name'] == me_nick
:
402 print_right_message(m
)
403 elif m
['recipient_screen_name'] == me_nick
:
404 print_left_message(m
)
407 def print_right_message(m
):
409 Print a message on the right of screen
411 h
, w
= os
.popen('stty size', 'r').read().split()
413 frame_width
= w
// 3 - dg
['frame_margin']
414 frame_width
= max(c
['THREAD_MIN_WIDTH'], frame_width
)
415 step
= frame_width
- 2 * dg
['frame_margin']
416 slicing
= textwrap
.wrap(m
['text'], step
)
417 spaces
= w
- frame_width
- dg
['frame_margin']
418 dotline
= ' ' * spaces
+ '-' * frame_width
419 dotline
= color_func(c
['MESSAGE']['me_frame'])(dotline
)
423 fill
= step
- len(line
)
424 screen_line
= ' ' * spaces
+ '| ' + line
+ ' ' * fill
+ ' '
425 if slicing
[-1] == line
:
426 screen_line
= screen_line
+ ' >'
428 screen_line
= screen_line
+ '|'
429 screen_line
= color_func(c
['MESSAGE']['me_frame'])(screen_line
)
430 printNicely(screen_line
)
433 date
= parser
.parse(m
['created_at'])
434 date
= arrow
.get(date
).to('local').datetime
435 clock_format
= '%Y/%m/%d %H:%M:%S'
437 clock_format
= c
['FORMAT']['MESSAGE']['CLOCK_FORMAT']
440 clock
= date
.strftime(clock_format
)
442 if m
['id'] not in c
['message_dict']:
443 c
['message_dict'].append(m
['id'])
444 rid
= len(c
['message_dict']) - 1
446 rid
= c
['message_dict'].index(m
['id'])
451 virtual_meta
= formater
= c
['THREAD_META_RIGHT']
452 virtual_meta
= clock
.join(virtual_meta
.split('#clock'))
453 virtual_meta
= id.join(virtual_meta
.split('#id'))
455 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
456 delimiter
= color_func(c
['MESSAGE']['clock'])(
457 clock
.join(word
.split('#clock')))
458 formater
= delimiter
.join(formater
.split(word
))
460 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
461 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
462 formater
= delimiter
.join(formater
.split(word
))
464 printNicely(red('Wrong format in config.'))
467 line
= ' ' * (w
- len(virtual_meta
) - dg
['frame_margin']) + meta
471 def print_left_message(m
):
473 Print a message on the left of screen
475 h
, w
= os
.popen('stty size', 'r').read().split()
477 frame_width
= w
// 3 - dg
['frame_margin']
478 frame_width
= max(c
['THREAD_MIN_WIDTH'], frame_width
)
479 step
= frame_width
- 2 * dg
['frame_margin']
480 slicing
= textwrap
.wrap(m
['text'], step
)
481 spaces
= dg
['frame_margin']
482 dotline
= ' ' * spaces
+ '-' * frame_width
483 dotline
= color_func(c
['MESSAGE']['partner_frame'])(dotline
)
487 fill
= step
- len(line
)
488 screen_line
= ' ' + line
+ ' ' * fill
+ ' |'
489 if slicing
[-1] == line
:
490 screen_line
= ' ' * (spaces
- 1) + '< ' + screen_line
492 screen_line
= ' ' * spaces
+ '|' + screen_line
493 screen_line
= color_func(c
['MESSAGE']['partner_frame'])(screen_line
)
494 printNicely(screen_line
)
497 date
= parser
.parse(m
['created_at'])
498 date
= arrow
.get(date
).to('local').datetime
499 clock_format
= '%Y/%m/%d %H:%M:%S'
501 clock_format
= c
['FORMAT']['MESSAGE']['CLOCK_FORMAT']
504 clock
= date
.strftime(clock_format
)
506 if m
['id'] not in c
['message_dict']:
507 c
['message_dict'].append(m
['id'])
508 rid
= len(c
['message_dict']) - 1
510 rid
= c
['message_dict'].index(m
['id'])
515 virtual_meta
= formater
= c
['THREAD_META_LEFT']
516 virtual_meta
= clock
.join(virtual_meta
.split('#clock'))
517 virtual_meta
= id.join(virtual_meta
.split('#id'))
519 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
520 delimiter
= color_func(c
['MESSAGE']['clock'])(
521 clock
.join(word
.split('#clock')))
522 formater
= delimiter
.join(formater
.split(word
))
524 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
525 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
526 formater
= delimiter
.join(formater
.split(word
))
528 printNicely(red('Wrong format in config.'))
531 line
= ' ' * dg
['frame_margin'] + meta
535 def print_message(m
):
540 sender_screen_name
= '@' + m
['sender_screen_name']
541 sender_name
= m
['sender']['name']
542 text
= unescape(m
['text'])
543 recipient_screen_name
= '@' + m
['recipient_screen_name']
544 recipient_name
= m
['recipient']['name']
546 date
= parser
.parse(m
['created_at'])
547 date
= arrow
.get(date
).to('local').datetime
548 clock_format
= '%Y/%m/%d %H:%M:%S'
550 clock_format
= c
['FORMAT']['MESSAGE']['CLOCK_FORMAT']
553 clock
= date
.strftime(clock_format
)
556 if mid
not in c
['message_dict']:
557 c
['message_dict'].append(mid
)
558 rid
= len(c
['message_dict']) - 1
560 rid
= c
['message_dict'].index(mid
)
563 sender_name
= cycle_color(sender_name
)
564 sender_nick
= color_func(c
['MESSAGE']['sender'])(sender_screen_name
)
565 recipient_name
= cycle_color(recipient_name
)
566 recipient_nick
= color_func(
567 c
['MESSAGE']['recipient'])(recipient_screen_name
)
568 to
= color_func(c
['MESSAGE']['to'])('>>>')
572 text
= ''.join(lmap(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
574 # Load config formater
576 formater
= c
['FORMAT']['MESSAGE']['DISPLAY']
577 formater
= sender_name
.join(formater
.split("#sender_name"))
578 formater
= sender_nick
.join(formater
.split("#sender_nick"))
579 formater
= to
.join(formater
.split("#to"))
580 formater
= recipient_name
.join(formater
.split("#recipient_name"))
581 formater
= recipient_nick
.join(formater
.split("#recipient_nick"))
582 formater
= text
.join(formater
.split("#message"))
584 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
585 delimiter
= color_func(c
['MESSAGE']['clock'])(
586 clock
.join(word
.split('#clock')))
587 formater
= delimiter
.join(formater
.split(word
))
589 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
590 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
591 formater
= delimiter
.join(formater
.split(word
))
593 printNicely(red('Wrong format in config.'))
597 printNicely(formater
)
600 def notify_retweet(t
):
605 created_at
= t
['created_at']
607 source_user
= cycle_color(source
['name']) + \
608 color_func(c
['NOTIFICATION']['source_nick'])(
609 ' @' + source
['screen_name'])
610 notify
= color_func(c
['NOTIFICATION']['notify'])(
611 'retweeted your tweet')
612 date
= parser
.parse(created_at
)
613 date
= arrow
.get(date
).to('local')
614 lang
, encode
= locale
.getdefaultlocale()
615 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
616 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
617 meta
= c
['NOTIFY_FORMAT']
618 meta
= source_user
.join(meta
.split('#source_user'))
619 meta
= notify
.join(meta
.split('#notify'))
620 meta
= clock
.join(meta
.split('#clock'))
624 draw(t
=t
['retweeted_status'], noti
=True)
627 def notify_favorite(e
):
629 Notify a favorite event
633 if target
['screen_name'] != c
['original_name']:
636 target_object
= e
['target_object']
637 created_at
= e
['created_at']
639 source_user
= cycle_color(source
['name']) + \
640 color_func(c
['NOTIFICATION']['source_nick'])(
641 ' @' + source
['screen_name'])
642 notify
= color_func(c
['NOTIFICATION']['notify'])(
643 'favorited your tweet')
644 date
= parser
.parse(created_at
)
645 date
= arrow
.get(date
).to('local')
646 lang
, encode
= locale
.getdefaultlocale()
647 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
648 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
649 meta
= c
['NOTIFY_FORMAT']
650 meta
= source_user
.join(meta
.split('#source_user'))
651 meta
= notify
.join(meta
.split('#notify'))
652 meta
= clock
.join(meta
.split('#clock'))
656 draw(t
=target_object
, noti
=True)
659 def notify_unfavorite(e
):
661 Notify a unfavorite event
665 if target
['screen_name'] != c
['original_name']:
668 target_object
= e
['target_object']
669 created_at
= e
['created_at']
671 source_user
= cycle_color(source
['name']) + \
672 color_func(c
['NOTIFICATION']['source_nick'])(
673 ' @' + source
['screen_name'])
674 notify
= color_func(c
['NOTIFICATION']['notify'])(
675 'unfavorited your tweet')
676 date
= parser
.parse(created_at
)
677 date
= arrow
.get(date
).to('local')
678 lang
, encode
= locale
.getdefaultlocale()
679 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
680 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
681 meta
= c
['NOTIFY_FORMAT']
682 meta
= source_user
.join(meta
.split('#source_user'))
683 meta
= notify
.join(meta
.split('#notify'))
684 meta
= clock
.join(meta
.split('#clock'))
688 draw(t
=target_object
, noti
=True)
691 def notify_follow(e
):
693 Notify a follow event
697 if target
['screen_name'] != c
['original_name']:
700 created_at
= e
['created_at']
702 source_user
= cycle_color(source
['name']) + \
703 color_func(c
['NOTIFICATION']['source_nick'])(
704 ' @' + source
['screen_name'])
705 notify
= color_func(c
['NOTIFICATION']['notify'])(
707 date
= parser
.parse(created_at
)
708 date
= arrow
.get(date
).to('local')
709 lang
, encode
= locale
.getdefaultlocale()
710 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
711 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
712 meta
= c
['NOTIFY_FORMAT']
713 meta
= source_user
.join(meta
.split('#source_user'))
714 meta
= notify
.join(meta
.split('#notify'))
715 meta
= clock
.join(meta
.split('#clock'))
721 def notify_list_member_added(e
):
723 Notify a list_member_added event
727 if target
['screen_name'] != c
['original_name']:
730 target_object
= [e
['target_object']] # list of Twitter list
731 created_at
= e
['created_at']
733 source_user
= cycle_color(source
['name']) + \
734 color_func(c
['NOTIFICATION']['source_nick'])(
735 ' @' + source
['screen_name'])
736 notify
= color_func(c
['NOTIFICATION']['notify'])(
737 'added you to a list')
738 date
= parser
.parse(created_at
)
739 date
= arrow
.get(date
).to('local')
740 lang
, encode
= locale
.getdefaultlocale()
741 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
742 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
743 meta
= c
['NOTIFY_FORMAT']
744 meta
= source_user
.join(meta
.split('#source_user'))
745 meta
= notify
.join(meta
.split('#notify'))
746 meta
= clock
.join(meta
.split('#clock'))
750 print_list(target_object
, noti
=True)
753 def notify_list_member_removed(e
):
755 Notify a list_member_removed event
759 if target
['screen_name'] != c
['original_name']:
762 target_object
= [e
['target_object']] # list of Twitter list
763 created_at
= e
['created_at']
765 source_user
= cycle_color(source
['name']) + \
766 color_func(c
['NOTIFICATION']['source_nick'])(
767 ' @' + source
['screen_name'])
768 notify
= color_func(c
['NOTIFICATION']['notify'])(
769 'removed you from a list')
770 date
= parser
.parse(created_at
)
771 date
= arrow
.get(date
).to('local')
772 lang
, encode
= locale
.getdefaultlocale()
773 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
774 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
775 meta
= c
['NOTIFY_FORMAT']
776 meta
= source_user
.join(meta
.split('#source_user'))
777 meta
= notify
.join(meta
.split('#notify'))
778 meta
= clock
.join(meta
.split('#clock'))
782 print_list(target_object
, noti
=True)
785 def notify_list_user_subscribed(e
):
787 Notify a list_user_subscribed event
791 if target
['screen_name'] != c
['original_name']:
794 target_object
= [e
['target_object']] # list of Twitter list
795 created_at
= e
['created_at']
797 source_user
= cycle_color(source
['name']) + \
798 color_func(c
['NOTIFICATION']['source_nick'])(
799 ' @' + source
['screen_name'])
800 notify
= color_func(c
['NOTIFICATION']['notify'])(
801 'subscribed to your list')
802 date
= parser
.parse(created_at
)
803 date
= arrow
.get(date
).to('local')
804 lang
, encode
= locale
.getdefaultlocale()
805 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
806 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
807 meta
= c
['NOTIFY_FORMAT']
808 meta
= source_user
.join(meta
.split('#source_user'))
809 meta
= notify
.join(meta
.split('#notify'))
810 meta
= clock
.join(meta
.split('#clock'))
814 print_list(target_object
, noti
=True)
817 def notify_list_user_unsubscribed(e
):
819 Notify a list_user_unsubscribed event
823 if target
['screen_name'] != c
['original_name']:
826 target_object
= [e
['target_object']] # list of Twitter list
827 created_at
= e
['created_at']
829 source_user
= cycle_color(source
['name']) + \
830 color_func(c
['NOTIFICATION']['source_nick'])(
831 ' @' + source
['screen_name'])
832 notify
= color_func(c
['NOTIFICATION']['notify'])(
833 'unsubscribed from your list')
834 date
= parser
.parse(created_at
)
835 date
= arrow
.get(date
).to('local')
836 lang
, encode
= locale
.getdefaultlocale()
837 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
838 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
839 meta
= c
['NOTIFY_FORMAT']
840 meta
= source_user
.join(meta
.split('#source_user'))
841 meta
= notify
.join(meta
.split('#notify'))
842 meta
= clock
.join(meta
.split('#clock'))
846 print_list(target_object
, noti
=True)
854 'retweet': notify_retweet
,
855 'favorite': notify_favorite
,
856 'unfavorite': notify_unfavorite
,
857 'follow': notify_follow
,
858 'list_member_added': notify_list_member_added
,
859 'list_member_removed': notify_list_member_removed
,
860 'list_user_subscribed': notify_list_user_subscribed
,
861 'list_user_unsubscribed': notify_list_user_unsubscribed
,
863 event_dict
[e
['event']](e
)
872 screen_name
= u
['screen_name']
873 description
= u
['description']
874 profile_image_url
= u
['profile_image_url']
875 location
= u
['location']
877 created_at
= u
['created_at']
878 statuses_count
= u
['statuses_count']
879 friends_count
= u
['friends_count']
880 followers_count
= u
['followers_count']
883 statuses_count
= color_func(
884 c
['PROFILE']['statuses_count'])(
885 str(statuses_count
) +
887 friends_count
= color_func(
888 c
['PROFILE']['friends_count'])(
891 followers_count
= color_func(
892 c
['PROFILE']['followers_count'])(
893 str(followers_count
) +
895 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
897 name
) + color_func(c
['PROFILE']['nick'])(' @' + screen_name
+ ' : ') + count
898 profile_image_raw_url
= 'Profile photo: ' + \
899 color_func(c
['PROFILE']['profile_image_url'])(profile_image_url
)
900 description
= ''.join(
901 lmap(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
902 description
= color_func(c
['PROFILE']['description'])(description
)
903 location
= 'Location : ' + color_func(c
['PROFILE']['location'])(location
)
904 url
= 'URL : ' + (color_func(c
['PROFILE']['url'])(url
) if url
else '')
905 date
= parser
.parse(created_at
)
906 lang
, encode
= locale
.getdefaultlocale()
907 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
908 clock
= 'Join at ' + color_func(c
['PROFILE']['clock'])(clock
)
911 line1
= u
"{u:>{uw}}".format(
915 line2
= u
"{p:>{pw}}".format(
916 p
=profile_image_raw_url
,
917 pw
=len(profile_image_raw_url
) + 4,
919 line3
= u
"{d:>{dw}}".format(
921 dw
=len(description
) + 4,
923 line4
= u
"{l:>{lw}}".format(
925 lw
=len(location
) + 4,
927 line5
= u
"{u:>{uw}}".format(
931 line6
= u
"{c:>{cw}}".format(
939 if c
['IMAGE_ON_TERM']:
941 response
= requests
.get(profile_image_url
)
942 image_to_display(BytesIO(response
.content
))
947 for line
in [line3
, line4
, line5
, line6
]:
952 def print_trends(trends
):
956 for topic
in trends
[:c
['TREND_MAX']]:
959 line
= cycle_color(name
) + ': ' + color_func(c
['TREND']['url'])(url
)
964 def print_list(group
, noti
=False):
970 name
= grp
['full_name']
971 name
= color_func(c
['GROUP']['name'])(name
+ ' : ')
972 member
= str(grp
['member_count'])
973 member
= color_func(c
['GROUP']['member'])(member
+ ' member')
974 subscriber
= str(grp
['subscriber_count'])
975 subscriber
= color_func(
976 c
['GROUP']['subscriber'])(
979 description
= grp
['description'].strip()
980 description
= color_func(c
['GROUP']['description'])(description
)
982 mode
= color_func(c
['GROUP']['mode'])('Type: ' + mode
)
983 created_at
= grp
['created_at']
984 date
= parser
.parse(created_at
)
985 lang
, encode
= locale
.getdefaultlocale()
986 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
987 clock
= 'Created at ' + color_func(c
['GROUP']['clock'])(clock
)
990 # Add spaces in begining of line if this is inside a notification
992 prefix
= ' ' * 2 + prefix
994 line1
= prefix
+ name
+ member
+ ' ' + subscriber
995 line2
= prefix
+ ' ' * 2 + description
996 line3
= prefix
+ ' ' * 2 + mode
997 line4
= prefix
+ ' ' * 2 + clock
1010 def show_calendar(month
, date
, rel
):
1012 Show the calendar in rainbow mode
1014 month
= random_rainbow(month
)
1015 date
= ' '.join([cycle_color(i
) for i
in date
.split(' ')])
1016 today
= str(int(os
.popen('date +\'%d\'').read().strip()))
1021 ary
= line
.split(' ')
1023 lambda x
: color_func(c
['CAL']['today'])(x
)
1025 else color_func(c
['CAL']['days'])(x
),
1027 printNicely(' '.join(ary
))
1030 def format_quote(tweet
):
1035 screen_name
= '@' + tweet
['user']['screen_name']
1036 text
= tweet
['text']
1037 # Validate quote format
1038 if '#owner' not in c
['QUOTE_FORMAT']:
1039 printNicely(light_magenta('Quote should contains #owner'))
1041 if '#comment' not in c
['QUOTE_FORMAT']:
1042 printNicely(light_magenta('Quote format should have #comment'))
1047 formater
= c
['QUOTE_FORMAT']
1048 formater
= screen_name
.join(formater
.split('#owner'))
1049 formater
= text
.join(formater
.split('#tweet'))
1050 formater
= u2str(formater
)
1053 # Highlight like a tweet
1054 notice
= formater
.split()
1056 lambda x
: light_green(x
)
1061 lambda x
: color_func(c
['TWEET']['rt'])(x
)
1065 notice
= lmap(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, notice
)
1067 lambda x
: color_func(c
['TWEET']['link'])(x
)
1072 lambda x
: color_func(c
['TWEET']['hashtag'])(x
)
1073 if x
.startswith('#')
1076 notice
= ' '.join(notice
)
1078 notice
= light_magenta('Quoting: "') + notice
+ light_magenta('"')
1083 # Start the color cycle