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 *
20 # Draw global variables
28 colors_shuffle
= [globals()[i
.encode('utf8')]
29 if not str(i
).isdigit()
30 else term_color(int(i
))
31 for i
in c
['CYCLE_COLOR']]
32 return itertools
.cycle(colors_shuffle
)
39 dg
['cyc'] = init_cycle()
45 Print a string with ordered color with each character
47 colors_shuffle
= [globals()[i
.encode('utf8')]
48 if not str(i
).isdigit()
49 else term_color(int(i
))
50 for i
in c
['CYCLE_COLOR']]
51 colored
= [colors_shuffle
[i
% 7](s
[i
]) for i
in xrange(len(s
))]
52 return ''.join(colored
)
55 def random_rainbow(s
):
57 Print a string with random color with each character
59 colors_shuffle
= [globals()[i
.encode('utf8')]
60 if not str(i
).isdigit()
61 else term_color(int(i
))
62 for i
in c
['CYCLE_COLOR']]
63 colored
= [random
.choice(colors_shuffle
)(i
) for i
in s
]
64 return ''.join(colored
)
73 if args
not in dg
['cache']:
74 dg
['cache'][args
] = func(*args
)
75 return dg
['cache'][args
]
82 Cycle the colors_shuffle
84 return next(dg
['cyc'])(s
)
91 fi
= figlet_format(text
, font
='doom')
93 [next(dg
['cyc'])(i
) for i
in fi
.split('\n')]
99 Check if config is changed
102 data
= get_all_config()
105 if data
[key
] != c
[key
]:
111 def validate_theme(theme
):
113 Validate a theme exists or not
115 # Theme changed check
116 files
= os
.listdir(os
.path
.dirname(__file__
) + '/colorset')
117 themes
= [f
.split('.')[0] for f
in files
if f
.split('.')[-1] == 'json']
118 return theme
in themes
121 def reload_theme(value
, prev
):
123 Check current theme and update if necessary
126 config
= os
.path
.dirname(
127 __file__
) + '/colorset/' + value
+ '.json'
129 data
= load_config(config
)
133 # Restart color cycle and update config
135 set_config('THEME', value
)
140 def color_func(func_name
):
142 Call color function base on name
144 if str(func_name
).isdigit():
145 return term_color(int(func_name
))
146 return globals()[func_name
]
149 def draw(t
, keyword
=None, humanize
=True, noti
=False, fil
=[], ig
=[]):
159 screen_name
= t
['user']['screen_name']
160 name
= t
['user']['name']
161 created_at
= t
['created_at']
162 favorited
= t
['favorited']
163 retweet_count
= t
['retweet_count']
164 favorite_count
= t
['favorite_count']
165 date
= parser
.parse(created_at
)
166 date
= arrow
.get(date
).to('local')
168 lang
, encode
= locale
.getdefaultlocale()
169 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
172 clock_format
= c
['FORMAT']['TWEET']['CLOCK_FORMAT']
174 clock_format
= '%Y/%m/%d %H:%M:%S'
175 clock
= date
.datetime
.strftime(clock_format
)
177 # Pull extended retweet text
179 text
= 'RT @' + t
['retweeted_status']['user']['screen_name'] + ': ' +\
180 t
['retweeted_status']['text']
181 # Display as a notification
182 target
= t
['retweeted_status']['user']['screen_name']
183 if all([target
== c
['original_name'], not noti
]):
184 # Add to evens for 'notification' command
185 t
['event'] = 'retweet'
186 c
['events'].append(t
)
192 # Unescape HTML character
193 text
= unescape(text
)
199 urls
= t
['entities']['urls']
201 expanded_url
.append(u
['expanded_url'])
210 media
= t
['entities']['media']
212 media_url
.append(m
['media_url'])
217 mytweet
= screen_name
== c
['original_name']
218 screen_name
= '@' + screen_name
219 fil
= list(set((fil
or []) + c
['ONLY_LIST']))
220 ig
= list(set((ig
or []) + c
['IGNORE_LIST']))
221 if fil
and screen_name
not in fil
:
223 if ig
and screen_name
in ig
:
227 if tid
not in c
['tweet_dict']:
228 c
['tweet_dict'].append(tid
)
229 rid
= len(c
['tweet_dict']) - 1
231 rid
= c
['tweet_dict'].index(tid
)
234 name
= cycle_color(name
)
236 nick
= color_func(c
['TWEET']['mynick'])(screen_name
)
238 nick
= color_func(c
['TWEET']['nick'])(screen_name
)
243 fav
= color_func(c
['TWEET']['favorited'])(u
'\u2605')
248 for index
in xrange(len(expanded_url
)):
250 lambda x
: expanded_url
[index
]
256 lambda x
: color_func(c
['TWEET']['rt'])(x
)
260 # Highlight screen_name
261 tweet
= lmap(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, tweet
)
264 lambda x
: color_func(c
['TWEET']['link'])(x
)
265 if x
.startswith('http')
270 lambda x
: color_func(c
['TWEET']['hashtag'])(x
)
276 tweet
= [color_func(c
['TWEET']['mytweet'])(x
)
280 x
.startswith('http'),
284 tweet
= ' '.join(tweet
)
286 roj
= re
.search(keyword
, tweet
, re
.IGNORECASE
)
289 ary
= tweet
.split(occur
)
290 delimiter
= color_func(c
['TWEET']['keyword'])(occur
)
291 tweet
= delimiter
.join(ary
)
293 # Load config formater
296 formater
= c
['FORMAT']['TWEET']['DISPLAY']
297 formater
= name
.join(formater
.split('#name'))
298 formater
= nick
.join(formater
.split('#nick'))
299 formater
= fav
.join(formater
.split('#fav'))
300 formater
= tweet
.join(formater
.split('#tweet'))
302 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
303 delimiter
= color_func(c
['TWEET']['clock'])(
304 clock
.join(word
.split('#clock')))
305 formater
= delimiter
.join(formater
.split(word
))
307 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
308 delimiter
= color_func(c
['TWEET']['id'])(id.join(word
.split('#id')))
309 formater
= delimiter
.join(formater
.split(word
))
310 # Change retweet count word
311 word
= [wo
for wo
in formater
.split() if '#rt_count' in wo
][0]
312 delimiter
= color_func(c
['TWEET']['retweet_count'])(
313 str(retweet_count
).join(word
.split('#rt_count')))
314 formater
= delimiter
.join(formater
.split(word
))
315 # Change favorites count word
316 word
= [wo
for wo
in formater
.split() if '#fa_count' in wo
][0]
317 delimiter
= color_func(c
['TWEET']['favorite_count'])(
318 str(favorite_count
).join(word
.split('#fa_count')))
319 formater
= delimiter
.join(formater
.split(word
))
320 formater
= emojize(formater
)
324 # Add spaces in begining of line if this is inside a notification
326 formater
= '\n '.join(formater
.split('\n'))
328 if formater
.startswith('\n'):
329 formater
= formater
[1:]
332 printNicely(formater
)
335 if c
['IMAGE_ON_TERM'] and media_url
:
338 response
= requests
.get(mu
)
339 image_to_display(BytesIO(response
.content
))
341 printNicely(red('Sorry, image link is broken'))
344 def print_threads(d
):
346 Print threads of messages
351 messages
= d
[partner
]
352 count
= len(messages
)
353 screen_name
= '@' + partner
[0]
355 screen_name
= color_func(c
['MESSAGE']['partner'])(screen_name
)
356 name
= cycle_color(name
)
357 thread_id
= color_func(c
['MESSAGE']['id'])('thread_id:' + str(id))
358 line
= ' ' * 2 + name
+ ' ' + screen_name
+ \
359 ' (' + str(count
) + ' message) ' + thread_id
367 def print_thread(partner
, me_nick
, me_name
):
369 Print a thread of messages
371 # Sort messages by time
372 messages
= dg
['thread'][partner
]
373 messages
.sort(key
=lambda x
: parser
.parse(x
['created_at']))
374 # Use legacy display on non-ascii text message
375 ms
= [m
['text'] for m
in messages
]
376 ums
= [m
for m
in ms
if not all(ord(c
) < 128 for c
in m
)]
382 # Print the first line
383 dg
['frame_margin'] = margin
= 2
384 partner_nick
= partner
[0]
385 partner_name
= partner
[1]
386 left_size
= len(partner_nick
) + len(partner_name
) + 2
387 right_size
= len(me_nick
) + len(me_name
) + 2
388 partner_nick
= color_func(c
['MESSAGE']['partner'])('@' + partner_nick
)
389 partner_name
= cycle_color(partner_name
)
390 me_screen_name
= color_func(c
['MESSAGE']['me'])('@' + me_nick
)
391 me_name
= cycle_color(me_name
)
392 left
= ' ' * margin
+ partner_name
+ ' ' + partner_nick
393 right
= me_name
+ ' ' + me_screen_name
+ ' ' * margin
394 h
, w
= os
.popen('stty size', 'r').read().split()
396 line
= '{}{}{}'.format(
397 left
, ' ' * (w
- left_size
- right_size
- 2 * margin
), right
)
403 if m
['sender_screen_name'] == me_nick
:
404 print_right_message(m
)
405 elif m
['recipient_screen_name'] == me_nick
:
406 print_left_message(m
)
409 def print_right_message(m
):
411 Print a message on the right of screen
413 h
, w
= os
.popen('stty size', 'r').read().split()
415 frame_width
= w
// 3 - dg
['frame_margin']
416 frame_width
= max(c
['THREAD_MIN_WIDTH'], frame_width
)
417 step
= frame_width
- 2 * dg
['frame_margin']
418 slicing
= textwrap
.wrap(m
['text'], step
)
419 spaces
= w
- frame_width
- dg
['frame_margin']
420 dotline
= ' ' * spaces
+ '-' * frame_width
421 dotline
= color_func(c
['MESSAGE']['me_frame'])(dotline
)
425 fill
= step
- len(line
)
426 screen_line
= ' ' * spaces
+ '| ' + line
+ ' ' * fill
+ ' '
427 if slicing
[-1] == line
:
428 screen_line
= screen_line
+ ' >'
430 screen_line
= screen_line
+ '|'
431 screen_line
= color_func(c
['MESSAGE']['me_frame'])(screen_line
)
432 printNicely(screen_line
)
435 date
= parser
.parse(m
['created_at'])
436 date
= arrow
.get(date
).to('local').datetime
437 clock_format
= '%Y/%m/%d %H:%M:%S'
439 clock_format
= c
['FORMAT']['MESSAGE']['CLOCK_FORMAT']
442 clock
= date
.strftime(clock_format
)
444 if m
['id'] not in c
['message_dict']:
445 c
['message_dict'].append(m
['id'])
446 rid
= len(c
['message_dict']) - 1
448 rid
= c
['message_dict'].index(m
['id'])
453 virtual_meta
= formater
= c
['THREAD_META_RIGHT']
454 virtual_meta
= clock
.join(virtual_meta
.split('#clock'))
455 virtual_meta
= id.join(virtual_meta
.split('#id'))
457 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
458 delimiter
= color_func(c
['MESSAGE']['clock'])(
459 clock
.join(word
.split('#clock')))
460 formater
= delimiter
.join(formater
.split(word
))
462 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
463 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
464 formater
= delimiter
.join(formater
.split(word
))
465 formater
= emojize(formater
)
467 printNicely(red('Wrong format in config.'))
470 line
= ' ' * (w
- len(virtual_meta
) - dg
['frame_margin']) + meta
474 def print_left_message(m
):
476 Print a message on the left of screen
478 h
, w
= os
.popen('stty size', 'r').read().split()
480 frame_width
= w
// 3 - dg
['frame_margin']
481 frame_width
= max(c
['THREAD_MIN_WIDTH'], frame_width
)
482 step
= frame_width
- 2 * dg
['frame_margin']
483 slicing
= textwrap
.wrap(m
['text'], step
)
484 spaces
= dg
['frame_margin']
485 dotline
= ' ' * spaces
+ '-' * frame_width
486 dotline
= color_func(c
['MESSAGE']['partner_frame'])(dotline
)
490 fill
= step
- len(line
)
491 screen_line
= ' ' + line
+ ' ' * fill
+ ' |'
492 if slicing
[-1] == line
:
493 screen_line
= ' ' * (spaces
- 1) + '< ' + screen_line
495 screen_line
= ' ' * spaces
+ '|' + screen_line
496 screen_line
= color_func(c
['MESSAGE']['partner_frame'])(screen_line
)
497 printNicely(screen_line
)
500 date
= parser
.parse(m
['created_at'])
501 date
= arrow
.get(date
).to('local').datetime
502 clock_format
= '%Y/%m/%d %H:%M:%S'
504 clock_format
= c
['FORMAT']['MESSAGE']['CLOCK_FORMAT']
507 clock
= date
.strftime(clock_format
)
509 if m
['id'] not in c
['message_dict']:
510 c
['message_dict'].append(m
['id'])
511 rid
= len(c
['message_dict']) - 1
513 rid
= c
['message_dict'].index(m
['id'])
518 virtual_meta
= formater
= c
['THREAD_META_LEFT']
519 virtual_meta
= clock
.join(virtual_meta
.split('#clock'))
520 virtual_meta
= id.join(virtual_meta
.split('#id'))
522 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
523 delimiter
= color_func(c
['MESSAGE']['clock'])(
524 clock
.join(word
.split('#clock')))
525 formater
= delimiter
.join(formater
.split(word
))
527 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
528 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
529 formater
= delimiter
.join(formater
.split(word
))
530 formater
= emojize(formater
)
532 printNicely(red('Wrong format in config.'))
535 line
= ' ' * dg
['frame_margin'] + meta
539 def print_message(m
):
544 sender_screen_name
= '@' + m
['sender_screen_name']
545 sender_name
= m
['sender']['name']
546 text
= unescape(m
['text'])
547 recipient_screen_name
= '@' + m
['recipient_screen_name']
548 recipient_name
= m
['recipient']['name']
550 date
= parser
.parse(m
['created_at'])
551 date
= arrow
.get(date
).to('local').datetime
552 clock_format
= '%Y/%m/%d %H:%M:%S'
554 clock_format
= c
['FORMAT']['MESSAGE']['CLOCK_FORMAT']
557 clock
= date
.strftime(clock_format
)
560 if mid
not in c
['message_dict']:
561 c
['message_dict'].append(mid
)
562 rid
= len(c
['message_dict']) - 1
564 rid
= c
['message_dict'].index(mid
)
567 sender_name
= cycle_color(sender_name
)
568 sender_nick
= color_func(c
['MESSAGE']['sender'])(sender_screen_name
)
569 recipient_name
= cycle_color(recipient_name
)
570 recipient_nick
= color_func(
571 c
['MESSAGE']['recipient'])(recipient_screen_name
)
572 to
= color_func(c
['MESSAGE']['to'])('>>>')
576 text
= ''.join(lmap(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
578 # Load config formater
580 formater
= c
['FORMAT']['MESSAGE']['DISPLAY']
581 formater
= sender_name
.join(formater
.split("#sender_name"))
582 formater
= sender_nick
.join(formater
.split("#sender_nick"))
583 formater
= to
.join(formater
.split("#to"))
584 formater
= recipient_name
.join(formater
.split("#recipient_name"))
585 formater
= recipient_nick
.join(formater
.split("#recipient_nick"))
586 formater
= text
.join(formater
.split("#message"))
588 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
589 delimiter
= color_func(c
['MESSAGE']['clock'])(
590 clock
.join(word
.split('#clock')))
591 formater
= delimiter
.join(formater
.split(word
))
593 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
594 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
595 formater
= delimiter
.join(formater
.split(word
))
596 formater
= emojize(formater
)
598 printNicely(red('Wrong format in config.'))
602 printNicely(formater
)
605 def notify_retweet(t
):
610 created_at
= t
['created_at']
612 source_user
= cycle_color(source
['name']) + \
613 color_func(c
['NOTIFICATION']['source_nick'])(
614 ' @' + source
['screen_name'])
615 notify
= color_func(c
['NOTIFICATION']['notify'])(
616 'retweeted your tweet')
617 date
= parser
.parse(created_at
)
618 date
= arrow
.get(date
).to('local')
619 lang
, encode
= locale
.getdefaultlocale()
620 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
621 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
622 meta
= c
['NOTIFY_FORMAT']
623 meta
= source_user
.join(meta
.split('#source_user'))
624 meta
= notify
.join(meta
.split('#notify'))
625 meta
= clock
.join(meta
.split('#clock'))
630 draw(t
=t
['retweeted_status'], noti
=True)
633 def notify_favorite(e
):
635 Notify a favorite event
639 if target
['screen_name'] != c
['original_name']:
642 target_object
= e
['target_object']
643 created_at
= e
['created_at']
645 source_user
= cycle_color(source
['name']) + \
646 color_func(c
['NOTIFICATION']['source_nick'])(
647 ' @' + source
['screen_name'])
648 notify
= color_func(c
['NOTIFICATION']['notify'])(
649 'favorited your tweet')
650 date
= parser
.parse(created_at
)
651 date
= arrow
.get(date
).to('local')
652 lang
, encode
= locale
.getdefaultlocale()
653 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
654 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
655 meta
= c
['NOTIFY_FORMAT']
656 meta
= source_user
.join(meta
.split('#source_user'))
657 meta
= notify
.join(meta
.split('#notify'))
658 meta
= clock
.join(meta
.split('#clock'))
663 draw(t
=target_object
, noti
=True)
666 def notify_unfavorite(e
):
668 Notify a unfavorite event
672 if target
['screen_name'] != c
['original_name']:
675 target_object
= e
['target_object']
676 created_at
= e
['created_at']
678 source_user
= cycle_color(source
['name']) + \
679 color_func(c
['NOTIFICATION']['source_nick'])(
680 ' @' + source
['screen_name'])
681 notify
= color_func(c
['NOTIFICATION']['notify'])(
682 'unfavorited your tweet')
683 date
= parser
.parse(created_at
)
684 date
= arrow
.get(date
).to('local')
685 lang
, encode
= locale
.getdefaultlocale()
686 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
687 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
688 meta
= c
['NOTIFY_FORMAT']
689 meta
= source_user
.join(meta
.split('#source_user'))
690 meta
= notify
.join(meta
.split('#notify'))
691 meta
= clock
.join(meta
.split('#clock'))
696 draw(t
=target_object
, noti
=True)
699 def notify_follow(e
):
701 Notify a follow event
705 if target
['screen_name'] != c
['original_name']:
708 created_at
= e
['created_at']
710 source_user
= cycle_color(source
['name']) + \
711 color_func(c
['NOTIFICATION']['source_nick'])(
712 ' @' + source
['screen_name'])
713 notify
= color_func(c
['NOTIFICATION']['notify'])(
715 date
= parser
.parse(created_at
)
716 date
= arrow
.get(date
).to('local')
717 lang
, encode
= locale
.getdefaultlocale()
718 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
719 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
720 meta
= c
['NOTIFY_FORMAT']
721 meta
= source_user
.join(meta
.split('#source_user'))
722 meta
= notify
.join(meta
.split('#notify'))
723 meta
= clock
.join(meta
.split('#clock'))
730 def notify_list_member_added(e
):
732 Notify a list_member_added event
736 if target
['screen_name'] != c
['original_name']:
739 target_object
= [e
['target_object']] # list of Twitter list
740 created_at
= e
['created_at']
742 source_user
= cycle_color(source
['name']) + \
743 color_func(c
['NOTIFICATION']['source_nick'])(
744 ' @' + source
['screen_name'])
745 notify
= color_func(c
['NOTIFICATION']['notify'])(
746 'added you to a list')
747 date
= parser
.parse(created_at
)
748 date
= arrow
.get(date
).to('local')
749 lang
, encode
= locale
.getdefaultlocale()
750 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
751 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
752 meta
= c
['NOTIFY_FORMAT']
753 meta
= source_user
.join(meta
.split('#source_user'))
754 meta
= notify
.join(meta
.split('#notify'))
755 meta
= clock
.join(meta
.split('#clock'))
760 print_list(target_object
, noti
=True)
763 def notify_list_member_removed(e
):
765 Notify a list_member_removed event
769 if target
['screen_name'] != c
['original_name']:
772 target_object
= [e
['target_object']] # list of Twitter list
773 created_at
= e
['created_at']
775 source_user
= cycle_color(source
['name']) + \
776 color_func(c
['NOTIFICATION']['source_nick'])(
777 ' @' + source
['screen_name'])
778 notify
= color_func(c
['NOTIFICATION']['notify'])(
779 'removed you from a list')
780 date
= parser
.parse(created_at
)
781 date
= arrow
.get(date
).to('local')
782 lang
, encode
= locale
.getdefaultlocale()
783 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
784 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
785 meta
= c
['NOTIFY_FORMAT']
786 meta
= source_user
.join(meta
.split('#source_user'))
787 meta
= notify
.join(meta
.split('#notify'))
788 meta
= clock
.join(meta
.split('#clock'))
793 print_list(target_object
, noti
=True)
796 def notify_list_user_subscribed(e
):
798 Notify a list_user_subscribed event
802 if target
['screen_name'] != c
['original_name']:
805 target_object
= [e
['target_object']] # list of Twitter list
806 created_at
= e
['created_at']
808 source_user
= cycle_color(source
['name']) + \
809 color_func(c
['NOTIFICATION']['source_nick'])(
810 ' @' + source
['screen_name'])
811 notify
= color_func(c
['NOTIFICATION']['notify'])(
812 'subscribed to your list')
813 date
= parser
.parse(created_at
)
814 date
= arrow
.get(date
).to('local')
815 lang
, encode
= locale
.getdefaultlocale()
816 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
817 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
818 meta
= c
['NOTIFY_FORMAT']
819 meta
= source_user
.join(meta
.split('#source_user'))
820 meta
= notify
.join(meta
.split('#notify'))
821 meta
= clock
.join(meta
.split('#clock'))
826 print_list(target_object
, noti
=True)
829 def notify_list_user_unsubscribed(e
):
831 Notify a list_user_unsubscribed event
835 if target
['screen_name'] != c
['original_name']:
838 target_object
= [e
['target_object']] # list of Twitter list
839 created_at
= e
['created_at']
841 source_user
= cycle_color(source
['name']) + \
842 color_func(c
['NOTIFICATION']['source_nick'])(
843 ' @' + source
['screen_name'])
844 notify
= color_func(c
['NOTIFICATION']['notify'])(
845 'unsubscribed from your list')
846 date
= parser
.parse(created_at
)
847 date
= arrow
.get(date
).to('local')
848 lang
, encode
= locale
.getdefaultlocale()
849 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
850 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
851 meta
= c
['NOTIFY_FORMAT']
852 meta
= source_user
.join(meta
.split('#source_user'))
853 meta
= notify
.join(meta
.split('#notify'))
854 meta
= clock
.join(meta
.split('#clock'))
859 print_list(target_object
, noti
=True)
867 'retweet': notify_retweet
,
868 'favorite': notify_favorite
,
869 'unfavorite': notify_unfavorite
,
870 'follow': notify_follow
,
871 'list_member_added': notify_list_member_added
,
872 'list_member_removed': notify_list_member_removed
,
873 'list_user_subscribed': notify_list_user_subscribed
,
874 'list_user_unsubscribed': notify_list_user_unsubscribed
,
876 event_dict
.get(e
['event'], lambda *args
: None)(e
)
885 screen_name
= u
['screen_name']
886 description
= u
['description']
887 profile_image_url
= u
['profile_image_url']
888 location
= u
['location']
890 created_at
= u
['created_at']
891 statuses_count
= u
['statuses_count']
892 friends_count
= u
['friends_count']
893 followers_count
= u
['followers_count']
896 statuses_count
= color_func(
897 c
['PROFILE']['statuses_count'])(
898 str(statuses_count
) +
900 friends_count
= color_func(
901 c
['PROFILE']['friends_count'])(
904 followers_count
= color_func(
905 c
['PROFILE']['followers_count'])(
906 str(followers_count
) +
908 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
910 name
) + color_func(c
['PROFILE']['nick'])(' @' + screen_name
+ ' : ') + count
911 profile_image_raw_url
= 'Profile photo: ' + \
912 color_func(c
['PROFILE']['profile_image_url'])(profile_image_url
)
913 description
= ''.join(
914 lmap(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
915 description
= color_func(c
['PROFILE']['description'])(description
)
916 location
= 'Location : ' + color_func(c
['PROFILE']['location'])(location
)
917 url
= 'URL : ' + (color_func(c
['PROFILE']['url'])(url
) if url
else '')
918 date
= parser
.parse(created_at
)
919 lang
, encode
= locale
.getdefaultlocale()
920 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
921 clock
= 'Join at ' + color_func(c
['PROFILE']['clock'])(clock
)
924 line1
= u
"{u:>{uw}}".format(
928 line2
= u
"{p:>{pw}}".format(
929 p
=profile_image_raw_url
,
930 pw
=len(profile_image_raw_url
) + 4,
932 line3
= u
"{d:>{dw}}".format(
934 dw
=len(description
) + 4,
936 line4
= u
"{l:>{lw}}".format(
938 lw
=len(location
) + 4,
940 line5
= u
"{u:>{uw}}".format(
944 line6
= u
"{c:>{cw}}".format(
952 if c
['IMAGE_ON_TERM']:
954 response
= requests
.get(profile_image_url
)
955 image_to_display(BytesIO(response
.content
))
960 for line
in [line3
, line4
, line5
, line6
]:
965 def print_trends(trends
):
969 for topic
in trends
[:c
['TREND_MAX']]:
972 line
= cycle_color(name
) + ': ' + color_func(c
['TREND']['url'])(url
)
977 def print_list(group
, noti
=False):
983 name
= grp
['full_name']
984 name
= color_func(c
['GROUP']['name'])(name
+ ' : ')
985 member
= str(grp
['member_count'])
986 member
= color_func(c
['GROUP']['member'])(member
+ ' member')
987 subscriber
= str(grp
['subscriber_count'])
988 subscriber
= color_func(
989 c
['GROUP']['subscriber'])(
992 description
= grp
['description'].strip()
993 description
= color_func(c
['GROUP']['description'])(description
)
995 mode
= color_func(c
['GROUP']['mode'])('Type: ' + mode
)
996 created_at
= grp
['created_at']
997 date
= parser
.parse(created_at
)
998 lang
, encode
= locale
.getdefaultlocale()
999 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
1000 clock
= 'Created at ' + color_func(c
['GROUP']['clock'])(clock
)
1003 # Add spaces in begining of line if this is inside a notification
1005 prefix
= ' ' * 2 + prefix
1007 line1
= prefix
+ name
+ member
+ ' ' + subscriber
1008 line2
= prefix
+ ' ' * 2 + description
1009 line3
= prefix
+ ' ' * 2 + mode
1010 line4
= prefix
+ ' ' * 2 + clock
1023 def show_calendar(month
, date
, rel
):
1025 Show the calendar in rainbow mode
1027 month
= random_rainbow(month
)
1028 date
= ' '.join([cycle_color(i
) for i
in date
.split(' ')])
1029 today
= str(int(os
.popen('date +\'%d\'').read().strip()))
1034 ary
= line
.split(' ')
1036 lambda x
: color_func(c
['CAL']['today'])(x
)
1038 else color_func(c
['CAL']['days'])(x
),
1040 printNicely(' '.join(ary
))
1043 def format_quote(tweet
):
1048 screen_name
= '@' + tweet
['user']['screen_name']
1049 text
= tweet
['text']
1050 # Validate quote format
1051 if '#owner' not in c
['QUOTE_FORMAT']:
1052 printNicely(light_magenta('Quote should contains #owner'))
1054 if '#comment' not in c
['QUOTE_FORMAT']:
1055 printNicely(light_magenta('Quote format should have #comment'))
1060 formater
= c
['QUOTE_FORMAT']
1061 formater
= screen_name
.join(formater
.split('#owner'))
1062 formater
= text
.join(formater
.split('#tweet'))
1063 formater
= u2str(formater
)
1064 formater
= emojize(formater
)
1067 # Highlight like a tweet
1068 notice
= formater
.split()
1070 lambda x
: light_green(x
)
1075 lambda x
: color_func(c
['TWEET']['rt'])(x
)
1079 notice
= lmap(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, notice
)
1081 lambda x
: color_func(c
['TWEET']['link'])(x
)
1086 lambda x
: color_func(c
['TWEET']['hashtag'])(x
)
1087 if x
.startswith('#')
1090 notice
= ' '.join(notice
)
1092 notice
= light_magenta('Quoting: "') + notice
+ light_magenta('"')
1097 # Start the color cycle