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()
41 dg
['humanize_unsupported'] = False
46 Print a string with ordered color with each character
48 colors_shuffle
= [globals()[i
.encode('utf8')]
49 if not str(i
).isdigit()
50 else term_color(int(i
))
51 for i
in c
['CYCLE_COLOR']]
52 colored
= [colors_shuffle
[i
% 7](s
[i
]) for i
in xrange(len(s
))]
53 return ''.join(colored
)
56 def random_rainbow(s
):
58 Print a string with random color with each character
60 colors_shuffle
= [globals()[i
.encode('utf8')]
61 if not str(i
).isdigit()
62 else term_color(int(i
))
63 for i
in c
['CYCLE_COLOR']]
64 colored
= [random
.choice(colors_shuffle
)(i
) for i
in s
]
65 return ''.join(colored
)
74 if args
not in dg
['cache']:
75 dg
['cache'][args
] = func(*args
)
76 return dg
['cache'][args
]
83 Cycle the colors_shuffle
85 return next(dg
['cyc'])(s
)
92 fi
= figlet_format(text
, font
='doom')
94 [next(dg
['cyc'])(i
) for i
in fi
.split('\n')]
100 Check if config is changed
103 data
= get_all_config()
106 if data
[key
] != c
[key
]:
112 def validate_theme(theme
):
114 Validate a theme exists or not
116 # Theme changed check
117 files
= os
.listdir(os
.path
.dirname(__file__
) + '/colorset')
118 themes
= [f
.split('.')[0] for f
in files
if f
.split('.')[-1] == 'json']
119 return theme
in themes
122 def reload_theme(value
, prev
):
124 Check current theme and update if necessary
127 config
= os
.path
.dirname(
128 __file__
) + '/colorset/' + value
+ '.json'
130 data
= load_config(config
)
134 # Restart color cycle and update config
136 set_config('THEME', value
)
141 def color_func(func_name
):
143 Call color function base on name
145 if str(func_name
).isdigit():
146 return term_color(int(func_name
))
147 return globals()[func_name
]
150 def fallback_humanize(date
, fallback_format
=None, use_fallback
=False):
152 Format date with arrow and a fallback format
154 # Convert to local timezone
155 date
= arrow
.get(date
).to('local')
156 # Set default fallback format
157 if not fallback_format
:
158 fallback_format
= '%Y/%m/%d %H:%M:%S'
159 # Determine using fallback format or not by a variable
161 return date
.datetime
.strftime(fallback_format
)
163 # Use Arrow's humanize function
164 lang
, encode
= locale
.getdefaultlocale()
165 clock
= date
.humanize(locale
=lang
)
167 # Notice at the 1st time only
168 if not dg
['humanize_unsupported']:
169 dg
['humanize_unsupported'] = True
171 light_magenta('Humanized date display method does not support your $LC_ALL.'))
172 # Fallback when LC_ALL is not supported
173 clock
= date
.datetime
.strftime(fallback_format
)
177 def draw(t
, keyword
=None, humanize
=True, noti
=False, fil
=[], ig
=[]):
187 screen_name
= t
['user']['screen_name']
188 name
= t
['user']['name']
189 created_at
= t
['created_at']
190 favorited
= t
['favorited']
191 retweet_count
= t
['retweet_count']
192 favorite_count
= t
['favorite_count']
194 date
= parser
.parse(created_at
)
196 clock_format
= c
['FORMAT']['TWEET']['CLOCK_FORMAT']
198 clock_format
= '%Y/%m/%d %H:%M:%S'
199 clock
= fallback_humanize(date
, clock_format
, not humanize
)
201 # Pull extended retweet text
203 text
= 'RT @' + t
['retweeted_status']['user']['screen_name'] + ': ' +\
204 t
['retweeted_status']['text']
205 # Display as a notification
206 target
= t
['retweeted_status']['user']['screen_name']
207 if all([target
== c
['original_name'], not noti
]):
208 # Add to evens for 'notification' command
209 t
['event'] = 'retweet'
210 c
['events'].append(t
)
216 # Unescape HTML character
217 text
= unescape(text
)
221 client
= client
.split('>')[-2].split('<')[0]
229 urls
= t
['entities']['urls']
231 expanded_url
.append(u
['expanded_url'])
240 media
= t
['entities']['media']
242 media_url
.append(m
['media_url'])
247 mytweet
= screen_name
== c
['original_name']
248 screen_name
= '@' + screen_name
249 fil
= list(set((fil
or []) + c
['ONLY_LIST']))
250 ig
= list(set((ig
or []) + c
['IGNORE_LIST']))
251 if fil
and screen_name
not in fil
:
253 if ig
and screen_name
in ig
:
257 if tid
not in c
['tweet_dict']:
258 c
['tweet_dict'].append(tid
)
259 rid
= len(c
['tweet_dict']) - 1
261 rid
= c
['tweet_dict'].index(tid
)
264 name
= cycle_color(name
)
266 nick
= color_func(c
['TWEET']['mynick'])(screen_name
)
268 nick
= color_func(c
['TWEET']['nick'])(screen_name
)
273 fav
= color_func(c
['TWEET']['favorited'])(u
'\u2605')
278 for index
in xrange(len(expanded_url
)):
280 lambda x
: expanded_url
[index
]
286 lambda x
: color_func(c
['TWEET']['rt'])(x
)
290 # Highlight screen_name
291 tweet
= lmap(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, tweet
)
294 lambda x
: color_func(c
['TWEET']['link'])(x
)
295 if x
.startswith('http')
300 lambda x
: color_func(c
['TWEET']['hashtag'])(x
)
306 tweet
= [color_func(c
['TWEET']['mytweet'])(x
)
310 x
.startswith('http'),
314 tweet
= ' '.join(tweet
)
316 roj
= re
.search(keyword
, tweet
, re
.IGNORECASE
)
319 ary
= tweet
.split(occur
)
320 delimiter
= color_func(c
['TWEET']['keyword'])(occur
)
321 tweet
= delimiter
.join(ary
)
323 # Load config formater
326 formater
= c
['FORMAT']['TWEET']['DISPLAY']
327 formater
= name
.join(formater
.split('#name'))
328 formater
= nick
.join(formater
.split('#nick'))
329 formater
= fav
.join(formater
.split('#fav'))
330 formater
= tweet
.join(formater
.split('#tweet'))
331 formater
= emojize(formater
)
333 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
334 delimiter
= color_func(c
['TWEET']['clock'])(
335 clock
.join(word
.split('#clock')))
336 formater
= delimiter
.join(formater
.split(word
))
338 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
339 delimiter
= color_func(c
['TWEET']['id'])(id.join(word
.split('#id')))
340 formater
= delimiter
.join(formater
.split(word
))
341 # Change retweet count word
342 word
= [wo
for wo
in formater
.split() if '#rt_count' in wo
][0]
343 delimiter
= color_func(c
['TWEET']['retweet_count'])(
344 str(retweet_count
).join(word
.split('#rt_count')))
345 formater
= delimiter
.join(formater
.split(word
))
346 # Change favorites count word
347 word
= [wo
for wo
in formater
.split() if '#fa_count' in wo
][0]
348 delimiter
= color_func(c
['TWEET']['favorite_count'])(
349 str(favorite_count
).join(word
.split('#fa_count')))
350 formater
= delimiter
.join(formater
.split(word
))
352 word
= [wo
for wo
in formater
.split() if '#client' in wo
][0]
353 delimiter
= color_func(c
['TWEET']['client'])(
354 client
.join(word
.split('#client')))
355 formater
= delimiter
.join(formater
.split(word
))
359 # Add spaces in begining of line if this is inside a notification
361 formater
= '\n '.join(formater
.split('\n'))
363 if formater
.startswith('\n'):
364 formater
= formater
[1:]
367 printNicely(formater
)
370 if c
['IMAGE_ON_TERM'] and media_url
:
373 response
= requests
.get(mu
)
374 image_to_display(BytesIO(response
.content
))
376 printNicely(red('Sorry, image link is broken'))
379 def print_threads(d
):
381 Print threads of messages
386 messages
= d
[partner
]
387 count
= len(messages
)
388 screen_name
= '@' + partner
[0]
390 screen_name
= color_func(c
['MESSAGE']['partner'])(screen_name
)
391 name
= cycle_color(name
)
392 thread_id
= color_func(c
['MESSAGE']['id'])('thread_id:' + str(id))
393 line
= ' ' * 2 + name
+ ' ' + screen_name
+ \
394 ' (' + str(count
) + ' message) ' + thread_id
402 def print_thread(partner
, me_nick
, me_name
):
404 Print a thread of messages
406 # Sort messages by time
407 messages
= dg
['thread'][partner
]
408 messages
.sort(key
=lambda x
: parser
.parse(x
['created_at']))
409 # Use legacy display on non-ascii text message
410 ms
= [m
['text'] for m
in messages
]
411 ums
= [m
for m
in ms
if not all(ord(c
) < 128 for c
in m
)]
417 # Print the first line
418 dg
['frame_margin'] = margin
= 2
419 partner_nick
= partner
[0]
420 partner_name
= partner
[1]
421 left_size
= len(partner_nick
) + len(partner_name
) + 2
422 right_size
= len(me_nick
) + len(me_name
) + 2
423 partner_nick
= color_func(c
['MESSAGE']['partner'])('@' + partner_nick
)
424 partner_name
= cycle_color(partner_name
)
425 me_screen_name
= color_func(c
['MESSAGE']['me'])('@' + me_nick
)
426 me_name
= cycle_color(me_name
)
427 left
= ' ' * margin
+ partner_name
+ ' ' + partner_nick
428 right
= me_name
+ ' ' + me_screen_name
+ ' ' * margin
429 h
, w
= os
.popen('stty size', 'r').read().split()
431 line
= '{}{}{}'.format(
432 left
, ' ' * (w
- left_size
- right_size
- 2 * margin
), right
)
438 if m
['sender_screen_name'] == me_nick
:
439 print_right_message(m
)
440 elif m
['recipient_screen_name'] == me_nick
:
441 print_left_message(m
)
444 def print_right_message(m
):
446 Print a message on the right of screen
448 h
, w
= os
.popen('stty size', 'r').read().split()
450 frame_width
= w
// 3 - dg
['frame_margin']
451 frame_width
= max(c
['THREAD_MIN_WIDTH'], frame_width
)
452 step
= frame_width
- 2 * dg
['frame_margin']
453 slicing
= textwrap
.wrap(m
['text'], step
)
454 spaces
= w
- frame_width
- dg
['frame_margin']
455 dotline
= ' ' * spaces
+ '-' * frame_width
456 dotline
= color_func(c
['MESSAGE']['me_frame'])(dotline
)
460 fill
= step
- len(line
)
461 screen_line
= ' ' * spaces
+ '| ' + line
+ ' ' * fill
+ ' '
462 if slicing
[-1] == line
:
463 screen_line
= screen_line
+ ' >'
465 screen_line
= screen_line
+ '|'
466 screen_line
= color_func(c
['MESSAGE']['me_frame'])(screen_line
)
467 printNicely(screen_line
)
470 date
= parser
.parse(m
['created_at'])
471 date
= arrow
.get(date
).to('local').datetime
472 clock_format
= '%Y/%m/%d %H:%M:%S'
474 clock_format
= c
['FORMAT']['MESSAGE']['CLOCK_FORMAT']
477 clock
= date
.strftime(clock_format
)
479 if m
['id'] not in c
['message_dict']:
480 c
['message_dict'].append(m
['id'])
481 rid
= len(c
['message_dict']) - 1
483 rid
= c
['message_dict'].index(m
['id'])
488 virtual_meta
= formater
= c
['THREAD_META_RIGHT']
489 virtual_meta
= clock
.join(virtual_meta
.split('#clock'))
490 virtual_meta
= id.join(virtual_meta
.split('#id'))
492 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
493 delimiter
= color_func(c
['MESSAGE']['clock'])(
494 clock
.join(word
.split('#clock')))
495 formater
= delimiter
.join(formater
.split(word
))
497 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
498 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
499 formater
= delimiter
.join(formater
.split(word
))
500 formater
= emojize(formater
)
502 printNicely(red('Wrong format in config.'))
505 line
= ' ' * (w
- len(virtual_meta
) - dg
['frame_margin']) + meta
509 def print_left_message(m
):
511 Print a message on the left of screen
513 h
, w
= os
.popen('stty size', 'r').read().split()
515 frame_width
= w
// 3 - dg
['frame_margin']
516 frame_width
= max(c
['THREAD_MIN_WIDTH'], frame_width
)
517 step
= frame_width
- 2 * dg
['frame_margin']
518 slicing
= textwrap
.wrap(m
['text'], step
)
519 spaces
= dg
['frame_margin']
520 dotline
= ' ' * spaces
+ '-' * frame_width
521 dotline
= color_func(c
['MESSAGE']['partner_frame'])(dotline
)
525 fill
= step
- len(line
)
526 screen_line
= ' ' + line
+ ' ' * fill
+ ' |'
527 if slicing
[-1] == line
:
528 screen_line
= ' ' * (spaces
- 1) + '< ' + screen_line
530 screen_line
= ' ' * spaces
+ '|' + screen_line
531 screen_line
= color_func(c
['MESSAGE']['partner_frame'])(screen_line
)
532 printNicely(screen_line
)
535 date
= parser
.parse(m
['created_at'])
536 date
= arrow
.get(date
).to('local').datetime
537 clock_format
= '%Y/%m/%d %H:%M:%S'
539 clock_format
= c
['FORMAT']['MESSAGE']['CLOCK_FORMAT']
542 clock
= date
.strftime(clock_format
)
544 if m
['id'] not in c
['message_dict']:
545 c
['message_dict'].append(m
['id'])
546 rid
= len(c
['message_dict']) - 1
548 rid
= c
['message_dict'].index(m
['id'])
553 virtual_meta
= formater
= c
['THREAD_META_LEFT']
554 virtual_meta
= clock
.join(virtual_meta
.split('#clock'))
555 virtual_meta
= id.join(virtual_meta
.split('#id'))
557 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
558 delimiter
= color_func(c
['MESSAGE']['clock'])(
559 clock
.join(word
.split('#clock')))
560 formater
= delimiter
.join(formater
.split(word
))
562 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
563 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
564 formater
= delimiter
.join(formater
.split(word
))
565 formater
= emojize(formater
)
567 printNicely(red('Wrong format in config.'))
570 line
= ' ' * dg
['frame_margin'] + meta
574 def print_message(m
):
579 sender_screen_name
= '@' + m
['sender_screen_name']
580 sender_name
= m
['sender']['name']
581 text
= unescape(m
['text'])
582 recipient_screen_name
= '@' + m
['recipient_screen_name']
583 recipient_name
= m
['recipient']['name']
585 date
= parser
.parse(m
['created_at'])
586 date
= arrow
.get(date
).to('local').datetime
587 clock_format
= '%Y/%m/%d %H:%M:%S'
589 clock_format
= c
['FORMAT']['MESSAGE']['CLOCK_FORMAT']
592 clock
= date
.strftime(clock_format
)
595 if mid
not in c
['message_dict']:
596 c
['message_dict'].append(mid
)
597 rid
= len(c
['message_dict']) - 1
599 rid
= c
['message_dict'].index(mid
)
602 sender_name
= cycle_color(sender_name
)
603 sender_nick
= color_func(c
['MESSAGE']['sender'])(sender_screen_name
)
604 recipient_name
= cycle_color(recipient_name
)
605 recipient_nick
= color_func(
606 c
['MESSAGE']['recipient'])(recipient_screen_name
)
607 to
= color_func(c
['MESSAGE']['to'])('>>>')
611 text
= ''.join(lmap(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
613 # Load config formater
615 formater
= c
['FORMAT']['MESSAGE']['DISPLAY']
616 formater
= sender_name
.join(formater
.split("#sender_name"))
617 formater
= sender_nick
.join(formater
.split("#sender_nick"))
618 formater
= to
.join(formater
.split("#to"))
619 formater
= recipient_name
.join(formater
.split("#recipient_name"))
620 formater
= recipient_nick
.join(formater
.split("#recipient_nick"))
621 formater
= text
.join(formater
.split("#message"))
623 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
624 delimiter
= color_func(c
['MESSAGE']['clock'])(
625 clock
.join(word
.split('#clock')))
626 formater
= delimiter
.join(formater
.split(word
))
628 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
629 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
630 formater
= delimiter
.join(formater
.split(word
))
631 formater
= emojize(formater
)
633 printNicely(red('Wrong format in config.'))
637 printNicely(formater
)
640 def notify_retweet(t
):
645 created_at
= t
['created_at']
647 source_user
= cycle_color(source
['name']) + \
648 color_func(c
['NOTIFICATION']['source_nick'])(
649 ' @' + source
['screen_name'])
650 notify
= color_func(c
['NOTIFICATION']['notify'])(
651 'retweeted your tweet')
652 date
= parser
.parse(created_at
)
653 clock
= fallback_humanize(date
)
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
=t
['retweeted_status'], noti
=True)
666 def notify_favorite(e
):
668 Notify a favorite 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 'favorited your tweet')
683 date
= parser
.parse(created_at
)
684 clock
= fallback_humanize(date
)
685 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
686 meta
= c
['NOTIFY_FORMAT']
687 meta
= source_user
.join(meta
.split('#source_user'))
688 meta
= notify
.join(meta
.split('#notify'))
689 meta
= clock
.join(meta
.split('#clock'))
694 draw(t
=target_object
, noti
=True)
697 def notify_unfavorite(e
):
699 Notify a unfavorite event
703 if target
['screen_name'] != c
['original_name']:
706 target_object
= e
['target_object']
707 created_at
= e
['created_at']
709 source_user
= cycle_color(source
['name']) + \
710 color_func(c
['NOTIFICATION']['source_nick'])(
711 ' @' + source
['screen_name'])
712 notify
= color_func(c
['NOTIFICATION']['notify'])(
713 'unfavorited your tweet')
714 date
= parser
.parse(created_at
)
715 clock
= fallback_humanize(date
)
716 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
717 meta
= c
['NOTIFY_FORMAT']
718 meta
= source_user
.join(meta
.split('#source_user'))
719 meta
= notify
.join(meta
.split('#notify'))
720 meta
= clock
.join(meta
.split('#clock'))
725 draw(t
=target_object
, noti
=True)
728 def notify_follow(e
):
730 Notify a follow event
734 if target
['screen_name'] != c
['original_name']:
737 created_at
= e
['created_at']
739 source_user
= cycle_color(source
['name']) + \
740 color_func(c
['NOTIFICATION']['source_nick'])(
741 ' @' + source
['screen_name'])
742 notify
= color_func(c
['NOTIFICATION']['notify'])(
744 date
= parser
.parse(created_at
)
745 clock
= fallback_humanize(date
)
746 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
747 meta
= c
['NOTIFY_FORMAT']
748 meta
= source_user
.join(meta
.split('#source_user'))
749 meta
= notify
.join(meta
.split('#notify'))
750 meta
= clock
.join(meta
.split('#clock'))
757 def notify_list_member_added(e
):
759 Notify a list_member_added event
763 if target
['screen_name'] != c
['original_name']:
766 target_object
= [e
['target_object']] # list of Twitter list
767 created_at
= e
['created_at']
769 source_user
= cycle_color(source
['name']) + \
770 color_func(c
['NOTIFICATION']['source_nick'])(
771 ' @' + source
['screen_name'])
772 notify
= color_func(c
['NOTIFICATION']['notify'])(
773 'added you to a list')
774 date
= parser
.parse(created_at
)
775 clock
= fallback_humanize(date
)
776 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
777 meta
= c
['NOTIFY_FORMAT']
778 meta
= source_user
.join(meta
.split('#source_user'))
779 meta
= notify
.join(meta
.split('#notify'))
780 meta
= clock
.join(meta
.split('#clock'))
785 print_list(target_object
, noti
=True)
788 def notify_list_member_removed(e
):
790 Notify a list_member_removed event
794 if target
['screen_name'] != c
['original_name']:
797 target_object
= [e
['target_object']] # list of Twitter list
798 created_at
= e
['created_at']
800 source_user
= cycle_color(source
['name']) + \
801 color_func(c
['NOTIFICATION']['source_nick'])(
802 ' @' + source
['screen_name'])
803 notify
= color_func(c
['NOTIFICATION']['notify'])(
804 'removed you from a list')
805 date
= parser
.parse(created_at
)
806 clock
= fallback_humanize(date
)
807 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
808 meta
= c
['NOTIFY_FORMAT']
809 meta
= source_user
.join(meta
.split('#source_user'))
810 meta
= notify
.join(meta
.split('#notify'))
811 meta
= clock
.join(meta
.split('#clock'))
816 print_list(target_object
, noti
=True)
819 def notify_list_user_subscribed(e
):
821 Notify a list_user_subscribed event
825 if target
['screen_name'] != c
['original_name']:
828 target_object
= [e
['target_object']] # list of Twitter list
829 created_at
= e
['created_at']
831 source_user
= cycle_color(source
['name']) + \
832 color_func(c
['NOTIFICATION']['source_nick'])(
833 ' @' + source
['screen_name'])
834 notify
= color_func(c
['NOTIFICATION']['notify'])(
835 'subscribed to your list')
836 date
= parser
.parse(created_at
)
837 clock
= fallback_humanize(date
)
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'))
847 print_list(target_object
, noti
=True)
850 def notify_list_user_unsubscribed(e
):
852 Notify a list_user_unsubscribed event
856 if target
['screen_name'] != c
['original_name']:
859 target_object
= [e
['target_object']] # list of Twitter list
860 created_at
= e
['created_at']
862 source_user
= cycle_color(source
['name']) + \
863 color_func(c
['NOTIFICATION']['source_nick'])(
864 ' @' + source
['screen_name'])
865 notify
= color_func(c
['NOTIFICATION']['notify'])(
866 'unsubscribed from your list')
867 date
= parser
.parse(created_at
)
868 clock
= fallback_humanize(date
)
869 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
870 meta
= c
['NOTIFY_FORMAT']
871 meta
= source_user
.join(meta
.split('#source_user'))
872 meta
= notify
.join(meta
.split('#notify'))
873 meta
= clock
.join(meta
.split('#clock'))
878 print_list(target_object
, noti
=True)
886 'retweet': notify_retweet
,
887 'favorite': notify_favorite
,
888 'unfavorite': notify_unfavorite
,
889 'follow': notify_follow
,
890 'list_member_added': notify_list_member_added
,
891 'list_member_removed': notify_list_member_removed
,
892 'list_user_subscribed': notify_list_user_subscribed
,
893 'list_user_unsubscribed': notify_list_user_unsubscribed
,
895 event_dict
.get(e
['event'], lambda *args
: None)(e
)
904 screen_name
= u
['screen_name']
905 description
= u
['description']
906 profile_image_url
= u
['profile_image_url']
907 location
= u
['location']
909 created_at
= u
['created_at']
910 statuses_count
= u
['statuses_count']
911 friends_count
= u
['friends_count']
912 followers_count
= u
['followers_count']
915 statuses_count
= color_func(
916 c
['PROFILE']['statuses_count'])(
917 str(statuses_count
) +
919 friends_count
= color_func(
920 c
['PROFILE']['friends_count'])(
923 followers_count
= color_func(
924 c
['PROFILE']['followers_count'])(
925 str(followers_count
) +
927 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
929 name
) + color_func(c
['PROFILE']['nick'])(' @' + screen_name
+ ' : ') + count
930 profile_image_raw_url
= 'Profile photo: ' + \
931 color_func(c
['PROFILE']['profile_image_url'])(profile_image_url
)
932 description
= ''.join(
933 lmap(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
934 description
= color_func(c
['PROFILE']['description'])(description
)
935 location
= 'Location : ' + color_func(c
['PROFILE']['location'])(location
)
936 url
= 'URL : ' + (color_func(c
['PROFILE']['url'])(url
) if url
else '')
937 date
= parser
.parse(created_at
)
938 clock
= fallback_humanize(date
)
939 clock
= 'Join at ' + color_func(c
['PROFILE']['clock'])(clock
)
942 line1
= u
"{u:>{uw}}".format(
946 line2
= u
"{p:>{pw}}".format(
947 p
=profile_image_raw_url
,
948 pw
=len(profile_image_raw_url
) + 4,
950 line3
= u
"{d:>{dw}}".format(
952 dw
=len(description
) + 4,
954 line4
= u
"{l:>{lw}}".format(
956 lw
=len(location
) + 4,
958 line5
= u
"{u:>{uw}}".format(
962 line6
= u
"{c:>{cw}}".format(
970 if c
['IMAGE_ON_TERM']:
972 response
= requests
.get(profile_image_url
)
973 image_to_display(BytesIO(response
.content
))
978 for line
in [line3
, line4
, line5
, line6
]:
983 def print_trends(trends
):
987 for topic
in trends
[:c
['TREND_MAX']]:
990 line
= cycle_color(name
) + ': ' + color_func(c
['TREND']['url'])(url
)
995 def print_list(group
, noti
=False):
1001 name
= grp
['full_name']
1002 name
= color_func(c
['GROUP']['name'])(name
+ ' : ')
1003 member
= str(grp
['member_count'])
1004 member
= color_func(c
['GROUP']['member'])(member
+ ' member')
1005 subscriber
= str(grp
['subscriber_count'])
1006 subscriber
= color_func(
1007 c
['GROUP']['subscriber'])(
1010 description
= grp
['description'].strip()
1011 description
= color_func(c
['GROUP']['description'])(description
)
1013 mode
= color_func(c
['GROUP']['mode'])('Type: ' + mode
)
1014 created_at
= grp
['created_at']
1015 date
= parser
.parse(created_at
)
1016 clock
= fallback_humanize(date
)
1017 clock
= 'Created at ' + color_func(c
['GROUP']['clock'])(clock
)
1020 # Add spaces in begining of line if this is inside a notification
1022 prefix
= ' ' * 2 + prefix
1024 line1
= prefix
+ name
+ member
+ ' ' + subscriber
1025 line2
= prefix
+ ' ' * 2 + description
1026 line3
= prefix
+ ' ' * 2 + mode
1027 line4
= prefix
+ ' ' * 2 + clock
1040 def show_calendar(month
, date
, rel
):
1042 Show the calendar in rainbow mode
1044 month
= random_rainbow(month
)
1045 date
= ' '.join([cycle_color(i
) for i
in date
.split(' ')])
1046 today
= str(int(os
.popen('date +\'%d\'').read().strip()))
1051 ary
= line
.split(' ')
1053 lambda x
: color_func(c
['CAL']['today'])(x
)
1055 else color_func(c
['CAL']['days'])(x
),
1057 printNicely(' '.join(ary
))
1060 def format_quote(tweet
):
1065 screen_name
= '@' + tweet
['user']['screen_name']
1066 text
= tweet
['text']
1067 # Validate quote format
1068 if '#owner' not in c
['QUOTE_FORMAT']:
1069 printNicely(light_magenta('Quote should contains #owner'))
1071 if '#comment' not in c
['QUOTE_FORMAT']:
1072 printNicely(light_magenta('Quote format should have #comment'))
1077 formater
= c
['QUOTE_FORMAT']
1078 formater
= screen_name
.join(formater
.split('#owner'))
1079 formater
= text
.join(formater
.split('#tweet'))
1080 formater
= u2str(formater
)
1081 formater
= emojize(formater
)
1084 # Highlight like a tweet
1085 notice
= formater
.split()
1087 lambda x
: light_green(x
)
1092 lambda x
: color_func(c
['TWEET']['rt'])(x
)
1096 notice
= lmap(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, notice
)
1098 lambda x
: color_func(c
['TWEET']['link'])(x
)
1103 lambda x
: color_func(c
['TWEET']['hashtag'])(x
)
1104 if x
.startswith('#')
1107 notice
= ' '.join(notice
)
1109 notice
= light_magenta('Quoting: "') + notice
+ light_magenta('"')
1114 # Start the color cycle