10 from io
import BytesIO
11 from twitter
.util
import printNicely
12 from functools
import wraps
13 from pyfiglet
import figlet_format
14 from dateutil
import parser
15 from .c_image
import *
18 from .py3patch
import *
21 # Draw global variables
29 colors_shuffle
= [globals()[i
.encode('utf8')]
30 if not str(i
).isdigit()
31 else term_color(int(i
))
32 for i
in c
['CYCLE_COLOR']]
33 return itertools
.cycle(colors_shuffle
)
40 dg
['cyc'] = init_cycle()
42 dg
['humanize_unsupported'] = False
47 Print a string with ordered color with each character
49 colors_shuffle
= [globals()[i
.encode('utf8')]
50 if not str(i
).isdigit()
51 else term_color(int(i
))
52 for i
in c
['CYCLE_COLOR']]
53 colored
= [colors_shuffle
[i
% 7](s
[i
]) for i
in xrange(len(s
))]
54 return ''.join(colored
)
57 def random_rainbow(s
):
59 Print a string with random color with each character
61 colors_shuffle
= [globals()[i
.encode('utf8')]
62 if not str(i
).isdigit()
63 else term_color(int(i
))
64 for i
in c
['CYCLE_COLOR']]
65 colored
= [random
.choice(colors_shuffle
)(i
) for i
in s
]
66 return ''.join(colored
)
75 if args
not in dg
['cache']:
76 dg
['cache'][args
] = func(*args
)
77 return dg
['cache'][args
]
84 Cycle the colors_shuffle
86 return next(dg
['cyc'])(s
)
93 fi
= figlet_format(text
, font
='doom')
95 [next(dg
['cyc'])(i
) for i
in fi
.split('\n')]
101 Check if config is changed
104 data
= get_all_config()
107 if data
[key
] != c
[key
]:
113 def validate_theme(theme
):
115 Validate a theme exists or not
117 # Theme changed check
118 files
= os
.listdir(os
.path
.dirname(__file__
) + '/colorset')
119 themes
= [f
.split('.')[0] for f
in files
if f
.split('.')[-1] == 'json']
120 return theme
in themes
123 def reload_theme(value
, prev
):
125 Check current theme and update if necessary
128 config
= os
.path
.dirname(
129 __file__
) + '/colorset/' + value
+ '.json'
131 data
= load_config(config
)
135 # Restart color cycle and update config
137 set_config('THEME', value
)
142 def color_func(func_name
):
144 Call color function base on name
146 if str(func_name
).isdigit():
147 return term_color(int(func_name
))
148 return globals()[func_name
]
151 def fallback_humanize(date
, fallback_format
=None, use_fallback
=False):
153 Format date with arrow and a fallback format
155 # Convert to local timezone
156 date
= arrow
.get(date
).to('local')
157 # Set default fallback format
158 if not fallback_format
:
159 fallback_format
= '%Y/%m/%d %H:%M:%S'
160 # Determine using fallback format or not by a variable
162 return date
.datetime
.strftime(fallback_format
)
164 # Use Arrow's humanize function
165 lang
, encode
= locale
.getdefaultlocale()
166 clock
= date
.humanize(locale
=lang
)
168 # Notice at the 1st time only
169 if not dg
['humanize_unsupported']:
170 dg
['humanize_unsupported'] = True
172 light_magenta('Humanized date display method does not support your $LC_ALL.'))
173 # Fallback when LC_ALL is not supported
174 clock
= date
.datetime
.strftime(fallback_format
)
178 def get_full_text(t
):
179 """Handle RTs and extended tweets to always display all the available text"""
181 if t
.get('retweeted_status'):
182 rt_status
= t
['retweeted_status']
183 if rt_status
.get('extended_tweet'):
184 elem
= rt_status
['extended_tweet']
187 rt_text
= elem
.get('full_text', elem
.get('text'))
188 t
['full_text'] = 'RT @' + rt_status
['user']['screen_name'] + ': ' + rt_text
189 elif t
.get('extended_tweet'):
190 t
['full_text'] = t
['extended_tweet']['full_text']
192 return t
.get('full_text', t
.get('text'))
195 def draw(t
, keyword
=None, humanize
=True, noti
=False, fil
=[], ig
=[]):
205 text
= get_full_text(t
)
206 screen_name
= t
['user']['screen_name']
207 name
= t
['user']['name']
208 created_at
= t
['created_at']
209 favorited
= t
['favorited']
210 retweet_count
= t
['retweet_count']
211 favorite_count
= t
['favorite_count']
213 date
= parser
.parse(created_at
)
215 clock_format
= c
['FORMAT']['TWEET']['CLOCK_FORMAT']
217 clock_format
= '%Y/%m/%d %H:%M:%S'
218 clock
= fallback_humanize(date
, clock_format
, not humanize
)
220 # Pull extended retweet text
222 # Display as a notification
223 target
= t
['retweeted_status']['user']['screen_name']
224 if all([target
== c
['original_name'], not noti
]):
225 # Add to evens for 'notification' command
226 t
['event'] = 'retweet'
227 c
['events'].append(t
)
233 # Unescape HTML character
234 text
= unescape(text
)
238 client
= client
.split('>')[-2].split('<')[0]
246 urls
= t
['entities']['urls']
248 expanded_url
.append(u
['expanded_url'])
257 media
= t
['entities']['media']
259 media_url
.append(m
['media_url'])
264 mytweet
= screen_name
== c
['original_name']
265 screen_name
= '@' + screen_name
266 fil
= list(set((fil
or []) + c
['ONLY_LIST']))
267 ig
= list(set((ig
or []) + c
['IGNORE_LIST']))
268 if fil
and screen_name
not in fil
:
270 if ig
and screen_name
in ig
:
274 if tid
not in c
['tweet_dict']:
275 c
['tweet_dict'].append(tid
)
276 rid
= len(c
['tweet_dict']) - 1
278 rid
= c
['tweet_dict'].index(tid
)
281 name
= cycle_color(name
)
283 nick
= color_func(c
['TWEET']['mynick'])(screen_name
)
285 nick
= color_func(c
['TWEET']['nick'])(screen_name
)
290 fav
= color_func(c
['TWEET']['favorited'])(u
'\u2605')
292 tweet
= text
.split(' ')
293 tweet
= [x
for x
in tweet
if x
!= '']
296 for index
in xrange(len(expanded_url
)):
298 lambda x
: expanded_url
[index
]
304 lambda x
: color_func(c
['TWEET']['rt'])(x
)
308 # Highlight screen_name
310 lambda x
: cycle_color(x
) if x
.lstrip().startswith('@') else x
, tweet
)
313 lambda x
: color_func(c
['TWEET']['link'])(x
)
314 if x
.lstrip().startswith('http')
319 lambda x
: color_func(c
['TWEET']['hashtag'])(x
)
320 if x
.lstrip().startswith('#')
325 tweet
= [color_func(c
['TWEET']['mytweet'])(x
)
329 x
.lstrip().startswith('http'),
330 x
.lstrip().startswith('#')])
333 tweet
= ' '.join(tweet
)
334 tweet
= '\n '.join(tweet
.split('\n'))
336 roj
= re
.search(keyword
, tweet
, re
.IGNORECASE
)
339 ary
= tweet
.split(occur
)
340 delimiter
= color_func(c
['TWEET']['keyword'])(occur
)
341 tweet
= delimiter
.join(ary
)
343 # Load config formater
346 formater
= c
['FORMAT']['TWEET']['DISPLAY']
347 formater
= name
.join(formater
.split('#name'))
348 formater
= nick
.join(formater
.split('#nick'))
349 formater
= fav
.join(formater
.split('#fav'))
350 formater
= tweet
.join(formater
.split('#tweet'))
351 formater
= emojize(formater
)
353 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
354 delimiter
= color_func(c
['TWEET']['clock'])(
355 clock
.join(word
.split('#clock')))
356 formater
= delimiter
.join(formater
.split(word
))
358 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
359 delimiter
= color_func(c
['TWEET']['id'])(id.join(word
.split('#id')))
360 formater
= delimiter
.join(formater
.split(word
))
361 # Change retweet count word
362 word
= [wo
for wo
in formater
.split() if '#rt_count' in wo
][0]
363 delimiter
= color_func(c
['TWEET']['retweet_count'])(
364 str(retweet_count
).join(word
.split('#rt_count')))
365 formater
= delimiter
.join(formater
.split(word
))
366 # Change favorites count word
367 word
= [wo
for wo
in formater
.split() if '#fa_count' in wo
][0]
368 delimiter
= color_func(c
['TWEET']['favorite_count'])(
369 str(favorite_count
).join(word
.split('#fa_count')))
370 formater
= delimiter
.join(formater
.split(word
))
372 word
= [wo
for wo
in formater
.split() if '#client' in wo
][0]
373 delimiter
= color_func(c
['TWEET']['client'])(
374 client
.join(word
.split('#client')))
375 formater
= delimiter
.join(formater
.split(word
))
379 # Add spaces in begining of line if this is inside a notification
381 formater
= '\n '.join(formater
.split('\n'))
383 if formater
.startswith('\n'):
384 formater
= formater
[1:]
387 printNicely(formater
)
390 if c
['IMAGE_ON_TERM'] and media_url
:
393 response
= requests
.get(mu
)
394 image_to_display(BytesIO(response
.content
))
396 printNicely(red('Sorry, image link is broken'))
399 def print_threads(d
):
401 Print threads of messages
406 messages
= d
[partner
]
407 count
= len(messages
)
408 screen_name
= '@' + partner
[0]
410 screen_name
= color_func(c
['MESSAGE']['partner'])(screen_name
)
411 name
= cycle_color(name
)
412 thread_id
= color_func(c
['MESSAGE']['id'])('thread_id:' + str(id))
413 line
= ' ' * 2 + name
+ ' ' + screen_name
+ \
414 ' (' + str(count
) + ' message) ' + thread_id
422 def print_thread(partner
, me_nick
, me_name
):
424 Print a thread of messages
426 # Sort messages by time
427 messages
= dg
['thread'][partner
]
428 messages
.sort(key
=lambda x
: int(x
['created_at']))
429 # Use legacy display on non-ascii text message
430 ms
= [m
['text'] for m
in messages
]
431 ums
= [m
for m
in ms
if not all(ord(c
) < 128 for c
in m
)]
437 # Print the first line
438 dg
['frame_margin'] = margin
= 2
439 partner_nick
= partner
[0]
440 partner_name
= partner
[1]
441 left_size
= len(partner_nick
) + len(partner_name
) + 2
442 right_size
= len(me_nick
) + len(me_name
) + 2
443 partner_nick
= color_func(c
['MESSAGE']['partner'])('@' + partner_nick
)
444 partner_name
= cycle_color(partner_name
)
445 me_screen_name
= color_func(c
['MESSAGE']['me'])('@' + me_nick
)
446 me_name
= cycle_color(me_name
)
447 left
= ' ' * margin
+ partner_name
+ ' ' + partner_nick
448 right
= me_name
+ ' ' + me_screen_name
+ ' ' * margin
449 h
, w
= os
.popen('stty size', 'r').read().split()
451 line
= '{}{}{}'.format(
452 left
, ' ' * (w
- left_size
- right_size
- 2 * margin
), right
)
458 if m
['sender_screen_name'] == me_nick
:
459 print_right_message(m
)
460 elif m
['recipient_screen_name'] == me_nick
:
461 print_left_message(m
)
464 def print_right_message(m
):
466 Print a message on the right of screen
468 h
, w
= os
.popen('stty size', 'r').read().split()
470 frame_width
= w
// 3 - dg
['frame_margin']
471 frame_width
= max(c
['THREAD_MIN_WIDTH'], frame_width
)
472 step
= frame_width
- 2 * dg
['frame_margin']
473 slicing
= textwrap
.wrap(m
['text'], step
)
474 spaces
= w
- frame_width
- dg
['frame_margin']
475 dotline
= ' ' * spaces
+ '-' * frame_width
476 dotline
= color_func(c
['MESSAGE']['me_frame'])(dotline
)
480 fill
= step
- len(line
)
481 screen_line
= ' ' * spaces
+ '| ' + line
+ ' ' * fill
+ ' '
482 if slicing
[-1] == line
:
483 screen_line
= screen_line
+ ' >'
485 screen_line
= screen_line
+ '|'
486 screen_line
= color_func(c
['MESSAGE']['me_frame'])(screen_line
)
487 printNicely(screen_line
)
490 date
= arrow
.get(int(m
['created_at'])/1000).to('local').datetime
# Read Unixtime in miliseconds
491 clock_format
= '%Y/%m/%d %H:%M:%S'
493 clock_format
= c
['FORMAT']['MESSAGE']['CLOCK_FORMAT']
496 clock
= date
.strftime(clock_format
)
498 if m
['id'] not in c
['message_dict']:
499 c
['message_dict'].append(m
['id'])
500 rid
= len(c
['message_dict']) - 1
502 rid
= c
['message_dict'].index(m
['id'])
507 virtual_meta
= formater
= c
['THREAD_META_RIGHT']
508 virtual_meta
= clock
.join(virtual_meta
.split('#clock'))
509 virtual_meta
= id.join(virtual_meta
.split('#id'))
511 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
512 delimiter
= color_func(c
['MESSAGE']['clock'])(
513 clock
.join(word
.split('#clock')))
514 formater
= delimiter
.join(formater
.split(word
))
516 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
517 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
518 formater
= delimiter
.join(formater
.split(word
))
519 formater
= emojize(formater
)
521 printNicely(red('Wrong format in config.'))
524 line
= ' ' * (w
- len(virtual_meta
) - dg
['frame_margin']) + meta
528 def print_left_message(m
):
530 Print a message on the left of screen
532 h
, w
= os
.popen('stty size', 'r').read().split()
534 frame_width
= w
// 3 - dg
['frame_margin']
535 frame_width
= max(c
['THREAD_MIN_WIDTH'], frame_width
)
536 step
= frame_width
- 2 * dg
['frame_margin']
537 slicing
= textwrap
.wrap(m
['text'], step
)
538 spaces
= dg
['frame_margin']
539 dotline
= ' ' * spaces
+ '-' * frame_width
540 dotline
= color_func(c
['MESSAGE']['partner_frame'])(dotline
)
544 fill
= step
- len(line
)
545 screen_line
= ' ' + line
+ ' ' * fill
+ ' |'
546 if slicing
[-1] == line
:
547 screen_line
= ' ' * (spaces
- 1) + '< ' + screen_line
549 screen_line
= ' ' * spaces
+ '|' + screen_line
550 screen_line
= color_func(c
['MESSAGE']['partner_frame'])(screen_line
)
551 printNicely(screen_line
)
554 date
= parser
.parse(m
['created_at'])
555 date
= arrow
.get(date
).to('local').datetime
556 clock_format
= '%Y/%m/%d %H:%M:%S'
558 clock_format
= c
['FORMAT']['MESSAGE']['CLOCK_FORMAT']
561 clock
= date
.strftime(clock_format
)
563 if m
['id'] not in c
['message_dict']:
564 c
['message_dict'].append(m
['id'])
565 rid
= len(c
['message_dict']) - 1
567 rid
= c
['message_dict'].index(m
['id'])
572 virtual_meta
= formater
= c
['THREAD_META_LEFT']
573 virtual_meta
= clock
.join(virtual_meta
.split('#clock'))
574 virtual_meta
= id.join(virtual_meta
.split('#id'))
576 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
577 delimiter
= color_func(c
['MESSAGE']['clock'])(
578 clock
.join(word
.split('#clock')))
579 formater
= delimiter
.join(formater
.split(word
))
581 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
582 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
583 formater
= delimiter
.join(formater
.split(word
))
584 formater
= emojize(formater
)
586 printNicely(red('Wrong format in config.'))
589 line
= ' ' * dg
['frame_margin'] + meta
593 def print_message(m
):
598 sender_screen_name
= '@' + m
['sender_screen_name']
599 sender_name
= m
['sender_name']
600 text
= unescape(m
['text'])
601 recipient_screen_name
= '@' + m
['recipient_screen_name']
602 recipient_name
= m
['recipient_name']
604 date
= parser
.parse(m
['created_at'])
605 date
= arrow
.get(date
).to('local').datetime
606 clock_format
= '%Y/%m/%d %H:%M:%S'
608 clock_format
= c
['FORMAT']['MESSAGE']['CLOCK_FORMAT']
611 clock
= date
.strftime(clock_format
)
614 if mid
not in c
['message_dict']:
615 c
['message_dict'].append(mid
)
616 rid
= len(c
['message_dict']) - 1
618 rid
= c
['message_dict'].index(mid
)
621 sender_name
= cycle_color(sender_name
)
622 sender_nick
= color_func(c
['MESSAGE']['sender'])(sender_screen_name
)
623 recipient_name
= cycle_color(recipient_name
)
624 recipient_nick
= color_func(
625 c
['MESSAGE']['recipient'])(recipient_screen_name
)
626 to
= color_func(c
['MESSAGE']['to'])('>>>')
630 text
= ''.join(lmap(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
632 # Load config formater
634 formater
= c
['FORMAT']['MESSAGE']['DISPLAY']
635 formater
= sender_name
.join(formater
.split("#sender_name"))
636 formater
= sender_nick
.join(formater
.split("#sender_nick"))
637 formater
= to
.join(formater
.split("#to"))
638 formater
= recipient_name
.join(formater
.split("#recipient_name"))
639 formater
= recipient_nick
.join(formater
.split("#recipient_nick"))
640 formater
= text
.join(formater
.split("#message"))
642 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
643 delimiter
= color_func(c
['MESSAGE']['clock'])(
644 clock
.join(word
.split('#clock')))
645 formater
= delimiter
.join(formater
.split(word
))
647 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
648 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
649 formater
= delimiter
.join(formater
.split(word
))
650 formater
= emojize(formater
)
652 printNicely(red('Wrong format in config.'))
656 printNicely(formater
)
659 def notify_retweet(t
):
664 created_at
= t
['created_at']
666 source_user
= cycle_color(source
['name']) + \
667 color_func(c
['NOTIFICATION']['source_nick'])(
668 ' @' + source
['screen_name'])
669 notify
= color_func(c
['NOTIFICATION']['notify'])(
670 'retweeted your tweet')
671 date
= parser
.parse(created_at
)
672 clock
= fallback_humanize(date
)
673 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
674 meta
= c
['NOTIFY_FORMAT']
675 meta
= source_user
.join(meta
.split('#source_user'))
676 meta
= notify
.join(meta
.split('#notify'))
677 meta
= clock
.join(meta
.split('#clock'))
682 draw(t
=t
['retweeted_status'], noti
=True)
685 def notify_favorite(e
):
687 Notify a favorite event
691 if target
['screen_name'] != c
['original_name']:
694 target_object
= e
['target_object']
695 created_at
= e
['created_at']
697 source_user
= cycle_color(source
['name']) + \
698 color_func(c
['NOTIFICATION']['source_nick'])(
699 ' @' + source
['screen_name'])
700 notify
= color_func(c
['NOTIFICATION']['notify'])(
701 'favorited your tweet')
702 date
= parser
.parse(created_at
)
703 clock
= fallback_humanize(date
)
704 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
705 meta
= c
['NOTIFY_FORMAT']
706 meta
= source_user
.join(meta
.split('#source_user'))
707 meta
= notify
.join(meta
.split('#notify'))
708 meta
= clock
.join(meta
.split('#clock'))
713 draw(t
=target_object
, noti
=True)
716 def notify_unfavorite(e
):
718 Notify a unfavorite event
722 if target
['screen_name'] != c
['original_name']:
725 target_object
= e
['target_object']
726 created_at
= e
['created_at']
728 source_user
= cycle_color(source
['name']) + \
729 color_func(c
['NOTIFICATION']['source_nick'])(
730 ' @' + source
['screen_name'])
731 notify
= color_func(c
['NOTIFICATION']['notify'])(
732 'unfavorited your tweet')
733 date
= parser
.parse(created_at
)
734 clock
= fallback_humanize(date
)
735 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
736 meta
= c
['NOTIFY_FORMAT']
737 meta
= source_user
.join(meta
.split('#source_user'))
738 meta
= notify
.join(meta
.split('#notify'))
739 meta
= clock
.join(meta
.split('#clock'))
744 draw(t
=target_object
, noti
=True)
747 def notify_follow(e
):
749 Notify a follow event
753 if target
['screen_name'] != c
['original_name']:
756 created_at
= e
['created_at']
758 source_user
= cycle_color(source
['name']) + \
759 color_func(c
['NOTIFICATION']['source_nick'])(
760 ' @' + source
['screen_name'])
761 notify
= color_func(c
['NOTIFICATION']['notify'])(
763 date
= parser
.parse(created_at
)
764 clock
= fallback_humanize(date
)
765 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
766 meta
= c
['NOTIFY_FORMAT']
767 meta
= source_user
.join(meta
.split('#source_user'))
768 meta
= notify
.join(meta
.split('#notify'))
769 meta
= clock
.join(meta
.split('#clock'))
776 def notify_list_member_added(e
):
778 Notify a list_member_added event
782 if target
['screen_name'] != c
['original_name']:
785 target_object
= [e
['target_object']] # list of Twitter list
786 created_at
= e
['created_at']
788 source_user
= cycle_color(source
['name']) + \
789 color_func(c
['NOTIFICATION']['source_nick'])(
790 ' @' + source
['screen_name'])
791 notify
= color_func(c
['NOTIFICATION']['notify'])(
792 'added you to a list')
793 date
= parser
.parse(created_at
)
794 clock
= fallback_humanize(date
)
795 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
796 meta
= c
['NOTIFY_FORMAT']
797 meta
= source_user
.join(meta
.split('#source_user'))
798 meta
= notify
.join(meta
.split('#notify'))
799 meta
= clock
.join(meta
.split('#clock'))
804 print_list(target_object
, noti
=True)
807 def notify_list_member_removed(e
):
809 Notify a list_member_removed event
813 if target
['screen_name'] != c
['original_name']:
816 target_object
= [e
['target_object']] # list of Twitter list
817 created_at
= e
['created_at']
819 source_user
= cycle_color(source
['name']) + \
820 color_func(c
['NOTIFICATION']['source_nick'])(
821 ' @' + source
['screen_name'])
822 notify
= color_func(c
['NOTIFICATION']['notify'])(
823 'removed you from a list')
824 date
= parser
.parse(created_at
)
825 clock
= fallback_humanize(date
)
826 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
827 meta
= c
['NOTIFY_FORMAT']
828 meta
= source_user
.join(meta
.split('#source_user'))
829 meta
= notify
.join(meta
.split('#notify'))
830 meta
= clock
.join(meta
.split('#clock'))
835 print_list(target_object
, noti
=True)
838 def notify_list_user_subscribed(e
):
840 Notify a list_user_subscribed event
844 if target
['screen_name'] != c
['original_name']:
847 target_object
= [e
['target_object']] # list of Twitter list
848 created_at
= e
['created_at']
850 source_user
= cycle_color(source
['name']) + \
851 color_func(c
['NOTIFICATION']['source_nick'])(
852 ' @' + source
['screen_name'])
853 notify
= color_func(c
['NOTIFICATION']['notify'])(
854 'subscribed to your list')
855 date
= parser
.parse(created_at
)
856 clock
= fallback_humanize(date
)
857 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
858 meta
= c
['NOTIFY_FORMAT']
859 meta
= source_user
.join(meta
.split('#source_user'))
860 meta
= notify
.join(meta
.split('#notify'))
861 meta
= clock
.join(meta
.split('#clock'))
866 print_list(target_object
, noti
=True)
869 def notify_list_user_unsubscribed(e
):
871 Notify a list_user_unsubscribed event
875 if target
['screen_name'] != c
['original_name']:
878 target_object
= [e
['target_object']] # list of Twitter list
879 created_at
= e
['created_at']
881 source_user
= cycle_color(source
['name']) + \
882 color_func(c
['NOTIFICATION']['source_nick'])(
883 ' @' + source
['screen_name'])
884 notify
= color_func(c
['NOTIFICATION']['notify'])(
885 'unsubscribed from your list')
886 date
= parser
.parse(created_at
)
887 clock
= fallback_humanize(date
)
888 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
889 meta
= c
['NOTIFY_FORMAT']
890 meta
= source_user
.join(meta
.split('#source_user'))
891 meta
= notify
.join(meta
.split('#notify'))
892 meta
= clock
.join(meta
.split('#clock'))
897 print_list(target_object
, noti
=True)
905 'retweet': notify_retweet
,
906 'favorite': notify_favorite
,
907 'unfavorite': notify_unfavorite
,
908 'follow': notify_follow
,
909 'list_member_added': notify_list_member_added
,
910 'list_member_removed': notify_list_member_removed
,
911 'list_user_subscribed': notify_list_user_subscribed
,
912 'list_user_unsubscribed': notify_list_user_unsubscribed
,
914 event_dict
.get(e
['event'], lambda *args
: None)(e
)
923 screen_name
= u
['screen_name']
924 description
= u
['description']
925 profile_image_url
= u
['profile_image_url']
926 location
= u
['location']
928 created_at
= u
['created_at']
929 statuses_count
= u
['statuses_count']
930 friends_count
= u
['friends_count']
931 followers_count
= u
['followers_count']
934 statuses_count
= color_func(
935 c
['PROFILE']['statuses_count'])(
936 str(statuses_count
) +
938 friends_count
= color_func(
939 c
['PROFILE']['friends_count'])(
942 followers_count
= color_func(
943 c
['PROFILE']['followers_count'])(
944 str(followers_count
) +
946 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
948 name
) + color_func(c
['PROFILE']['nick'])(' @' + screen_name
+ ' : ') + count
949 profile_image_raw_url
= 'Profile photo: ' + \
950 color_func(c
['PROFILE']['profile_image_url'])(profile_image_url
)
951 description
= ''.join(
952 lmap(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
953 description
= color_func(c
['PROFILE']['description'])(description
)
954 location
= 'Location : ' + color_func(c
['PROFILE']['location'])(location
)
955 url
= 'URL : ' + (color_func(c
['PROFILE']['url'])(url
) if url
else '')
956 date
= parser
.parse(created_at
)
957 clock
= fallback_humanize(date
)
958 clock
= 'Joined ' + color_func(c
['PROFILE']['clock'])(clock
)
961 line1
= u
"{u:>{uw}}".format(
965 line2
= u
"{p:>{pw}}".format(
966 p
=profile_image_raw_url
,
967 pw
=len(profile_image_raw_url
) + 4,
969 line3
= u
"{d:>{dw}}".format(
971 dw
=len(description
) + 4,
973 line4
= u
"{l:>{lw}}".format(
975 lw
=len(location
) + 4,
977 line5
= u
"{u:>{uw}}".format(
981 line6
= u
"{c:>{cw}}".format(
989 if c
['IMAGE_ON_TERM']:
991 response
= requests
.get(profile_image_url
)
992 image_to_display(BytesIO(response
.content
))
997 for line
in [line3
, line4
, line5
, line6
]:
1002 def print_trends(trends
):
1006 for topic
in trends
[:c
['TREND_MAX']]:
1007 name
= topic
['name']
1009 line
= cycle_color(name
) + ': ' + color_func(c
['TREND']['url'])(url
)
1014 def print_list(group
, noti
=False):
1020 name
= grp
['full_name']
1021 name
= color_func(c
['GROUP']['name'])(name
+ ' : ')
1022 member
= str(grp
['member_count'])
1023 member
= color_func(c
['GROUP']['member'])(member
+ ' member')
1024 subscriber
= str(grp
['subscriber_count'])
1025 subscriber
= color_func(
1026 c
['GROUP']['subscriber'])(
1029 description
= grp
['description'].strip()
1030 description
= color_func(c
['GROUP']['description'])(description
)
1032 mode
= color_func(c
['GROUP']['mode'])('Type: ' + mode
)
1033 created_at
= grp
['created_at']
1034 date
= parser
.parse(created_at
)
1035 clock
= fallback_humanize(date
)
1036 clock
= 'Created at ' + color_func(c
['GROUP']['clock'])(clock
)
1039 # Add spaces in begining of line if this is inside a notification
1041 prefix
= ' ' * 2 + prefix
1043 line1
= prefix
+ name
+ member
+ ' ' + subscriber
1044 line2
= prefix
+ ' ' * 2 + description
1045 line3
= prefix
+ ' ' * 2 + mode
1046 line4
= prefix
+ ' ' * 2 + clock
1059 def show_calendar(month
, date
, rel
):
1061 Show the calendar in rainbow mode
1063 month
= random_rainbow(month
)
1064 date
= ' '.join([cycle_color(i
) for i
in date
.split(' ')])
1065 today
= str(int(os
.popen('date +\'%d\'').read().strip()))
1070 ary
= line
.split(' ')
1072 lambda x
: color_func(c
['CAL']['today'])(x
)
1074 else color_func(c
['CAL']['days'])(x
),
1076 printNicely(' '.join(ary
))
1079 def format_quote(tweet
):
1084 screen_name
= tweet
['user']['screen_name']
1085 text
= get_full_text(tweet
)
1086 tid
= str( tweet
['id'] )
1088 # Validate quote format
1089 if '#owner' not in c
['QUOTE_FORMAT']:
1090 printNicely(light_magenta('Quote should contains #owner'))
1092 if '#comment' not in c
['QUOTE_FORMAT']:
1093 printNicely(light_magenta('Quote format should have #comment'))
1099 formater
= c
['QUOTE_FORMAT']
1101 formater
= formater
.replace('#owner', screen_name
)
1102 formater
= formater
.replace('#tweet', text
)
1103 formater
= formater
.replace('#tid', tid
)
1105 formater
= emojize(formater
)
1108 # Highlight like a tweet
1109 notice
= formater
.split()
1111 lambda x
: light_green(x
)
1116 lambda x
: color_func(c
['TWEET']['rt'])(x
)
1120 notice
= lmap(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, notice
)
1122 lambda x
: color_func(c
['TWEET']['link'])(x
)
1127 lambda x
: color_func(c
['TWEET']['hashtag'])(x
)
1128 if x
.startswith('#')
1131 notice
= ' '.join(notice
)
1133 notice
= light_magenta('Quoting: "') + notice
+ light_magenta('"')
1138 # Start the color cycle