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']
183 # Unescape HTML character
184 text
= unescape(text
)
190 urls
= t
['entities']['urls']
192 expanded_url
.append(u
['expanded_url'])
201 media
= t
['entities']['media']
203 media_url
.append(m
['media_url'])
208 mytweet
= screen_name
== c
['original_name']
209 screen_name
= '@' + screen_name
210 fil
= list(set((fil
or []) + c
['ONLY_LIST']))
211 ig
= list(set((ig
or []) + c
['IGNORE_LIST']))
212 if fil
and screen_name
not in fil
:
214 if ig
and screen_name
in ig
:
218 if tid
not in c
['tweet_dict']:
219 c
['tweet_dict'].append(tid
)
220 rid
= len(c
['tweet_dict']) - 1
222 rid
= c
['tweet_dict'].index(tid
)
225 name
= cycle_color(name
)
227 nick
= color_func(c
['TWEET']['mynick'])(screen_name
)
229 nick
= color_func(c
['TWEET']['nick'])(screen_name
)
234 fav
= color_func(c
['TWEET']['favorited'])(u
'\u2605')
239 for index
in xrange(len(expanded_url
)):
241 lambda x
: expanded_url
[index
]
247 lambda x
: color_func(c
['TWEET']['rt'])(x
)
251 # Highlight screen_name
252 tweet
= lmap(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, tweet
)
255 lambda x
: color_func(c
['TWEET']['link'])(x
)
256 if x
.startswith('http')
261 lambda x
: color_func(c
['TWEET']['hashtag'])(x
)
267 tweet
= [color_func(c
['TWEET']['mytweet'])(x
)
271 x
.startswith('http'),
275 tweet
= ' '.join(tweet
)
277 roj
= re
.search(keyword
, tweet
, re
.IGNORECASE
)
280 ary
= tweet
.split(occur
)
281 delimiter
= color_func(c
['TWEET']['keyword'])(occur
)
282 tweet
= delimiter
.join(ary
)
284 # Load config formater
287 formater
= c
['FORMAT']['TWEET']['DISPLAY']
288 formater
= name
.join(formater
.split('#name'))
289 formater
= nick
.join(formater
.split('#nick'))
290 formater
= fav
.join(formater
.split('#fav'))
291 formater
= tweet
.join(formater
.split('#tweet'))
293 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
294 delimiter
= color_func(c
['TWEET']['clock'])(
295 clock
.join(word
.split('#clock')))
296 formater
= delimiter
.join(formater
.split(word
))
298 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
299 delimiter
= color_func(c
['TWEET']['id'])(id.join(word
.split('#id')))
300 formater
= delimiter
.join(formater
.split(word
))
301 # Change retweet count word
302 word
= [wo
for wo
in formater
.split() if '#rt_count' in wo
][0]
303 delimiter
= color_func(c
['TWEET']['retweet_count'])(
304 str(retweet_count
).join(word
.split('#rt_count')))
305 formater
= delimiter
.join(formater
.split(word
))
306 # Change favorites count word
307 word
= [wo
for wo
in formater
.split() if '#fa_count' in wo
][0]
308 delimiter
= color_func(c
['TWEET']['favorite_count'])(
309 str(favorite_count
).join(word
.split('#fa_count')))
310 formater
= delimiter
.join(formater
.split(word
))
314 # Add spaces in begining of line if this is inside a notification
316 formater
= '\n '.join(formater
.split('\n'))
319 printNicely(formater
)
322 if c
['IMAGE_ON_TERM'] and media_url
:
325 response
= requests
.get(mu
)
326 image_to_display(BytesIO(response
.content
))
328 printNicely(red('Sorry, image link is broken'))
331 def print_threads(d
):
333 Print threads of messages
338 messages
= d
[partner
]
339 count
= len(messages
)
340 screen_name
= '@' + partner
[0]
342 screen_name
= color_func(c
['MESSAGE']['partner'])(screen_name
)
343 name
= cycle_color(name
)
344 thread_id
= color_func(c
['MESSAGE']['id'])('thread_id:' + str(id))
345 line
= ' ' * 2 + name
+ ' ' + screen_name
+ \
346 ' (' + str(count
) + ' message) ' + thread_id
354 def print_thread(partner
, me_nick
, me_name
):
356 Print a thread of messages
358 # Sort messages by time
359 messages
= dg
['thread'][partner
]
360 messages
.sort(key
=lambda x
: parser
.parse(x
['created_at']))
361 # Use legacy display on non-ascii text message
362 ms
= [m
['text'] for m
in messages
]
363 ums
= [m
for m
in ms
if not all(ord(c
) < 128 for c
in m
)]
369 # Print the first line
370 dg
['frame_margin'] = margin
= 2
371 partner_nick
= partner
[0]
372 partner_name
= partner
[1]
373 left_size
= len(partner_nick
) + len(partner_name
) + 2
374 right_size
= len(me_nick
) + len(me_name
) + 2
375 partner_nick
= color_func(c
['MESSAGE']['partner'])('@' + partner_nick
)
376 partner_name
= cycle_color(partner_name
)
377 me_screen_name
= color_func(c
['MESSAGE']['me'])('@' + me_nick
)
378 me_name
= cycle_color(me_name
)
379 left
= ' ' * margin
+ partner_name
+ ' ' + partner_nick
380 right
= me_name
+ ' ' + me_screen_name
+ ' ' * margin
381 h
, w
= os
.popen('stty size', 'r').read().split()
383 line
= '{}{}{}'.format(
384 left
, ' ' * (w
- left_size
- right_size
- 2 * margin
), right
)
390 if m
['sender_screen_name'] == me_nick
:
391 print_right_message(m
)
392 elif m
['recipient_screen_name'] == me_nick
:
393 print_left_message(m
)
396 def print_right_message(m
):
398 Print a message on the right of screen
400 h
, w
= os
.popen('stty size', 'r').read().split()
402 frame_width
= w
// 3 - dg
['frame_margin']
403 frame_width
= max(c
['THREAD_MIN_WIDTH'], frame_width
)
404 step
= frame_width
- 2 * dg
['frame_margin']
405 slicing
= textwrap
.wrap(m
['text'], step
)
406 spaces
= w
- frame_width
- dg
['frame_margin']
407 dotline
= ' ' * spaces
+ '-' * frame_width
408 dotline
= color_func(c
['MESSAGE']['me_frame'])(dotline
)
412 fill
= step
- len(line
)
413 screen_line
= ' ' * spaces
+ '| ' + line
+ ' ' * fill
+ ' '
414 if slicing
[-1] == line
:
415 screen_line
= screen_line
+ ' >'
417 screen_line
= screen_line
+ '|'
418 screen_line
= color_func(c
['MESSAGE']['me_frame'])(screen_line
)
419 printNicely(screen_line
)
422 date
= parser
.parse(m
['created_at'])
423 date
= arrow
.get(date
).to('local').datetime
424 clock_format
= '%Y/%m/%d %H:%M:%S'
426 clock_format
= c
['FORMAT']['MESSAGE']['CLOCK_FORMAT']
429 clock
= date
.strftime(clock_format
)
431 if m
['id'] not in c
['message_dict']:
432 c
['message_dict'].append(m
['id'])
433 rid
= len(c
['message_dict']) - 1
435 rid
= c
['message_dict'].index(m
['id'])
440 virtual_meta
= formater
= c
['THREAD_META_RIGHT']
441 virtual_meta
= clock
.join(virtual_meta
.split('#clock'))
442 virtual_meta
= id.join(virtual_meta
.split('#id'))
444 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
445 delimiter
= color_func(c
['MESSAGE']['clock'])(
446 clock
.join(word
.split('#clock')))
447 formater
= delimiter
.join(formater
.split(word
))
449 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
450 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
451 formater
= delimiter
.join(formater
.split(word
))
453 printNicely(red('Wrong format in config.'))
456 line
= ' ' * (w
- len(virtual_meta
) - dg
['frame_margin']) + meta
460 def print_left_message(m
):
462 Print a message on the left of screen
464 h
, w
= os
.popen('stty size', 'r').read().split()
466 frame_width
= w
// 3 - dg
['frame_margin']
467 frame_width
= max(c
['THREAD_MIN_WIDTH'], frame_width
)
468 step
= frame_width
- 2 * dg
['frame_margin']
469 slicing
= textwrap
.wrap(m
['text'], step
)
470 spaces
= dg
['frame_margin']
471 dotline
= ' ' * spaces
+ '-' * frame_width
472 dotline
= color_func(c
['MESSAGE']['partner_frame'])(dotline
)
476 fill
= step
- len(line
)
477 screen_line
= ' ' + line
+ ' ' * fill
+ ' |'
478 if slicing
[-1] == line
:
479 screen_line
= ' ' * (spaces
- 1) + '< ' + screen_line
481 screen_line
= ' ' * spaces
+ '|' + screen_line
482 screen_line
= color_func(c
['MESSAGE']['partner_frame'])(screen_line
)
483 printNicely(screen_line
)
486 date
= parser
.parse(m
['created_at'])
487 date
= arrow
.get(date
).to('local').datetime
488 clock_format
= '%Y/%m/%d %H:%M:%S'
490 clock_format
= c
['FORMAT']['MESSAGE']['CLOCK_FORMAT']
493 clock
= date
.strftime(clock_format
)
495 if m
['id'] not in c
['message_dict']:
496 c
['message_dict'].append(m
['id'])
497 rid
= len(c
['message_dict']) - 1
499 rid
= c
['message_dict'].index(m
['id'])
504 virtual_meta
= formater
= c
['THREAD_META_LEFT']
505 virtual_meta
= clock
.join(virtual_meta
.split('#clock'))
506 virtual_meta
= id.join(virtual_meta
.split('#id'))
508 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
509 delimiter
= color_func(c
['MESSAGE']['clock'])(
510 clock
.join(word
.split('#clock')))
511 formater
= delimiter
.join(formater
.split(word
))
513 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
514 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
515 formater
= delimiter
.join(formater
.split(word
))
517 printNicely(red('Wrong format in config.'))
520 line
= ' ' * dg
['frame_margin'] + meta
524 def print_message(m
):
529 sender_screen_name
= '@' + m
['sender_screen_name']
530 sender_name
= m
['sender']['name']
531 text
= unescape(m
['text'])
532 recipient_screen_name
= '@' + m
['recipient_screen_name']
533 recipient_name
= m
['recipient']['name']
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
)
545 if mid
not in c
['message_dict']:
546 c
['message_dict'].append(mid
)
547 rid
= len(c
['message_dict']) - 1
549 rid
= c
['message_dict'].index(mid
)
552 sender_name
= cycle_color(sender_name
)
553 sender_nick
= color_func(c
['MESSAGE']['sender'])(sender_screen_name
)
554 recipient_name
= cycle_color(recipient_name
)
555 recipient_nick
= color_func(
556 c
['MESSAGE']['recipient'])(recipient_screen_name
)
557 to
= color_func(c
['MESSAGE']['to'])('>>>')
561 text
= ''.join(lmap(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
563 # Load config formater
565 formater
= c
['FORMAT']['MESSAGE']['DISPLAY']
566 formater
= sender_name
.join(formater
.split("#sender_name"))
567 formater
= sender_nick
.join(formater
.split("#sender_nick"))
568 formater
= to
.join(formater
.split("#to"))
569 formater
= recipient_name
.join(formater
.split("#recipient_name"))
570 formater
= recipient_nick
.join(formater
.split("#recipient_nick"))
571 formater
= text
.join(formater
.split("#message"))
573 word
= [wo
for wo
in formater
.split() if '#clock' in wo
][0]
574 delimiter
= color_func(c
['MESSAGE']['clock'])(
575 clock
.join(word
.split('#clock')))
576 formater
= delimiter
.join(formater
.split(word
))
578 word
= [wo
for wo
in formater
.split() if '#id' in wo
][0]
579 delimiter
= color_func(c
['MESSAGE']['id'])(id.join(word
.split('#id')))
580 formater
= delimiter
.join(formater
.split(word
))
582 printNicely(red('Wrong format in config.'))
586 printNicely(formater
)
589 def notify_favorite(e
):
591 Notify a favorite event
595 if target
['screen_name'] != c
['original_name']:
598 target_object
= e
['target_object']
599 created_at
= e
['created_at']
601 source_user
= cycle_color(source
['name']) + \
602 color_func(c
['NOTIFICATION']['source_nick'])(
603 ' @' + source
['screen_name'])
604 notify
= color_func(c
['NOTIFICATION']['notify'])(' favorited your tweet ')
605 date
= parser
.parse(created_at
)
606 date
= arrow
.get(date
).to('local')
607 lang
, encode
= locale
.getdefaultlocale()
608 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
609 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
610 meta
= ' ' * 2 + source_user
+ notify
+ clock
614 draw(t
=target_object
, noti
=True)
617 def notify_unfavorite(e
):
619 Notify a unfavorite event
623 if target
['screen_name'] != c
['original_name']:
626 target_object
= e
['target_object']
627 created_at
= e
['created_at']
629 source_user
= cycle_color(source
['name']) + \
630 color_func(c
['NOTIFICATION']['source_nick'])(
631 ' @' + source
['screen_name'])
632 notify
= color_func(c
['NOTIFICATION']['notify'])(
633 ' unfavorited your tweet ')
634 date
= parser
.parse(created_at
)
635 date
= arrow
.get(date
).to('local')
636 lang
, encode
= locale
.getdefaultlocale()
637 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
638 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
639 meta
= ' ' * 2 + source_user
+ notify
+ clock
643 draw(t
=target_object
, noti
=True)
646 def notify_follow(e
):
648 Notify a follow event
652 if target
['screen_name'] != c
['original_name']:
655 created_at
= e
['created_at']
657 source_user
= cycle_color(source
['name']) + \
658 color_func(c
['NOTIFICATION']['source_nick'])(
659 ' @' + source
['screen_name'])
660 notify
= color_func(c
['NOTIFICATION']['notify'])(' followed you ')
661 date
= parser
.parse(created_at
)
662 date
= arrow
.get(date
).to('local')
663 lang
, encode
= locale
.getdefaultlocale()
664 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
665 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
666 meta
= ' ' * 2 + source_user
+ notify
+ clock
672 def notify_list_member_added(e
):
674 Notify a list_member_added event
678 if target
['screen_name'] != c
['original_name']:
681 target_object
= [e
['target_object']] # list of Twitter list
682 created_at
= e
['created_at']
684 source_user
= cycle_color(source
['name']) + \
685 color_func(c
['NOTIFICATION']['source_nick'])(
686 ' @' + source
['screen_name'])
687 notify
= color_func(c
['NOTIFICATION']['notify'])(' added you to a list ')
688 date
= parser
.parse(created_at
)
689 date
= arrow
.get(date
).to('local')
690 lang
, encode
= locale
.getdefaultlocale()
691 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
692 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
693 meta
= ' ' * 2 + source_user
+ notify
+ clock
697 print_list(target_object
, noti
=True)
700 def notify_list_member_removed(e
):
702 Notify a list_member_removed event
706 if target
['screen_name'] != c
['original_name']:
709 target_object
= [e
['target_object']] # list of Twitter list
710 created_at
= e
['created_at']
712 source_user
= cycle_color(source
['name']) + \
713 color_func(c
['NOTIFICATION']['source_nick'])(
714 ' @' + source
['screen_name'])
715 notify
= color_func(c
['NOTIFICATION']['notify'])(
716 ' removed you from a list ')
717 date
= parser
.parse(created_at
)
718 date
= arrow
.get(date
).to('local')
719 lang
, encode
= locale
.getdefaultlocale()
720 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
721 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
722 meta
= ' ' * 2 + source_user
+ notify
+ clock
726 print_list(target_object
, noti
=True)
729 def notify_list_user_subscribed(e
):
731 Notify a list_user_subscribed event
735 if target
['screen_name'] != c
['original_name']:
738 target_object
= [e
['target_object']] # list of Twitter list
739 created_at
= e
['created_at']
741 source_user
= cycle_color(source
['name']) + \
742 color_func(c
['NOTIFICATION']['source_nick'])(
743 ' @' + source
['screen_name'])
744 notify
= color_func(c
['NOTIFICATION']['notify'])(
745 ' subscribed to your list ')
746 date
= parser
.parse(created_at
)
747 date
= arrow
.get(date
).to('local')
748 lang
, encode
= locale
.getdefaultlocale()
749 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
750 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
751 meta
= ' ' * 2 + source_user
+ notify
+ clock
755 print_list(target_object
, noti
=True)
758 def notify_list_user_unsubscribed(e
):
760 Notify a list_user_unsubscribed event
764 if target
['screen_name'] != c
['original_name']:
767 target_object
= [e
['target_object']] # list of Twitter list
768 created_at
= e
['created_at']
770 source_user
= cycle_color(source
['name']) + \
771 color_func(c
['NOTIFICATION']['source_nick'])(
772 ' @' + source
['screen_name'])
773 notify
= color_func(c
['NOTIFICATION']['notify'])(
774 ' unsubscribed from your list ')
775 date
= parser
.parse(created_at
)
776 date
= arrow
.get(date
).to('local')
777 lang
, encode
= locale
.getdefaultlocale()
778 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
779 clock
= color_func(c
['NOTIFICATION']['clock'])(clock
)
780 meta
= ' ' * 2 + source_user
+ notify
+ clock
784 print_list(target_object
, noti
=True)
792 'favorite': notify_favorite
,
793 'unfavorite': notify_unfavorite
,
794 'follow': notify_follow
,
795 'list_member_added': notify_list_member_added
,
796 'list_member_removed': notify_list_member_removed
,
797 'list_user_subscribed': notify_list_user_subscribed
,
798 'list_user_unsubscribed': notify_list_user_unsubscribed
,
800 event_dict
[e
['event']](e
)
809 screen_name
= u
['screen_name']
810 description
= u
['description']
811 profile_image_url
= u
['profile_image_url']
812 location
= u
['location']
814 created_at
= u
['created_at']
815 statuses_count
= u
['statuses_count']
816 friends_count
= u
['friends_count']
817 followers_count
= u
['followers_count']
820 statuses_count
= color_func(
821 c
['PROFILE']['statuses_count'])(
822 str(statuses_count
) +
824 friends_count
= color_func(
825 c
['PROFILE']['friends_count'])(
828 followers_count
= color_func(
829 c
['PROFILE']['followers_count'])(
830 str(followers_count
) +
832 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
834 name
) + color_func(c
['PROFILE']['nick'])(' @' + screen_name
+ ' : ') + count
835 profile_image_raw_url
= 'Profile photo: ' + \
836 color_func(c
['PROFILE']['profile_image_url'])(profile_image_url
)
837 description
= ''.join(
838 lmap(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
839 description
= color_func(c
['PROFILE']['description'])(description
)
840 location
= 'Location : ' + color_func(c
['PROFILE']['location'])(location
)
841 url
= 'URL : ' + (color_func(c
['PROFILE']['url'])(url
) if url
else '')
842 date
= parser
.parse(created_at
)
843 lang
, encode
= locale
.getdefaultlocale()
844 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
845 clock
= 'Join at ' + color_func(c
['PROFILE']['clock'])(clock
)
848 line1
= u
"{u:>{uw}}".format(
852 line2
= u
"{p:>{pw}}".format(
853 p
=profile_image_raw_url
,
854 pw
=len(profile_image_raw_url
) + 4,
856 line3
= u
"{d:>{dw}}".format(
858 dw
=len(description
) + 4,
860 line4
= u
"{l:>{lw}}".format(
862 lw
=len(location
) + 4,
864 line5
= u
"{u:>{uw}}".format(
868 line6
= u
"{c:>{cw}}".format(
876 if c
['IMAGE_ON_TERM']:
878 response
= requests
.get(profile_image_url
)
879 image_to_display(BytesIO(response
.content
))
884 for line
in [line3
, line4
, line5
, line6
]:
889 def print_trends(trends
):
893 for topic
in trends
[:c
['TREND_MAX']]:
896 line
= cycle_color(name
) + ': ' + color_func(c
['TREND']['url'])(url
)
901 def print_list(group
, noti
=False):
907 name
= grp
['full_name']
908 name
= color_func(c
['GROUP']['name'])(name
+ ' : ')
909 member
= str(grp
['member_count'])
910 member
= color_func(c
['GROUP']['member'])(member
+ ' member')
911 subscriber
= str(grp
['subscriber_count'])
912 subscriber
= color_func(
913 c
['GROUP']['subscriber'])(
916 description
= grp
['description'].strip()
917 description
= color_func(c
['GROUP']['description'])(description
)
919 mode
= color_func(c
['GROUP']['mode'])('Type: ' + mode
)
920 created_at
= grp
['created_at']
921 date
= parser
.parse(created_at
)
922 lang
, encode
= locale
.getdefaultlocale()
923 clock
= arrow
.get(date
).to('local').humanize(locale
=lang
)
924 clock
= 'Created at ' + color_func(c
['GROUP']['clock'])(clock
)
927 # Add spaces in begining of line if this is inside a notification
929 prefix
= ' ' * 2 + prefix
931 line1
= prefix
+ name
+ member
+ ' ' + subscriber
932 line2
= prefix
+ ' ' * 2 + description
933 line3
= prefix
+ ' ' * 2 + mode
934 line4
= prefix
+ ' ' * 2 + clock
946 def show_calendar(month
, date
, rel
):
948 Show the calendar in rainbow mode
950 month
= random_rainbow(month
)
951 date
= ' '.join([cycle_color(i
) for i
in date
.split(' ')])
952 today
= str(int(os
.popen('date +\'%d\'').read().strip()))
957 ary
= line
.split(' ')
959 lambda x
: color_func(c
['CAL']['today'])(x
)
961 else color_func(c
['CAL']['days'])(x
),
963 printNicely(' '.join(ary
))
966 def format_quote(tweet
):
971 screen_name
= '@' + tweet
['user']['screen_name']
973 # Validate quote format
974 if '#owner' not in c
['QUOTE_FORMAT']:
975 printNicely(light_magenta('Quote should contains #owner'))
977 if '#comment' not in c
['QUOTE_FORMAT']:
978 printNicely(light_magenta('Quote format should have #comment'))
983 formater
= c
['QUOTE_FORMAT']
984 formater
= screen_name
.join(formater
.split('#owner'))
985 formater
= text
.join(formater
.split('#tweet'))
986 formater
= u2str(formater
)
989 # Highlight like a tweet
990 notice
= formater
.split()
992 lambda x
: light_green(x
)
997 lambda x
: color_func(c
['TWEET']['rt'])(x
)
1001 notice
= lmap(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, notice
)
1003 lambda x
: color_func(c
['TWEET']['link'])(x
)
1008 lambda x
: color_func(c
['TWEET']['hashtag'])(x
)
1009 if x
.startswith('#')
1012 notice
= ' '.join(notice
)
1014 notice
= light_magenta('Quoting: "') + notice
+ light_magenta('"')
1019 # Start the color cycle