improve search query
[rainbowstream.git] / rainbowstream / draw.py
1 import random
2 import textwrap
3 import itertools
4 import requests
5 import locale
6 import arrow
7 import re
8 import os
9
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 *
15 from .colors import *
16 from .config import *
17 from .py3patch import *
18
19 # Draw global variables
20 dg = {}
21
22
23 def init_cycle():
24 """
25 Init the cycle
26 """
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)
32
33
34 def start_cycle():
35 """
36 Notify from rainbow
37 """
38 dg['cyc'] = init_cycle()
39 dg['cache'] = {}
40
41
42 def order_rainbow(s):
43 """
44 Print a string with ordered color with each character
45 """
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)
52
53
54 def random_rainbow(s):
55 """
56 Print a string with random color with each character
57 """
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)
64
65
66 def Memoize(func):
67 """
68 Memoize decorator
69 """
70 @wraps(func)
71 def wrapper(*args):
72 if args not in dg['cache']:
73 dg['cache'][args] = func(*args)
74 return dg['cache'][args]
75 return wrapper
76
77
78 @Memoize
79 def cycle_color(s):
80 """
81 Cycle the colors_shuffle
82 """
83 return next(dg['cyc'])(s)
84
85
86 def ascii_art(text):
87 """
88 Draw the Ascii Art
89 """
90 fi = figlet_format(text, font='doom')
91 print('\n'.join(
92 [next(dg['cyc'])(i) for i in fi.split('\n')]
93 ))
94
95
96 def check_config():
97 """
98 Check if config is changed
99 """
100 changed = False
101 data = get_all_config()
102 for key in c:
103 if key in data:
104 if data[key] != c[key]:
105 changed = True
106 if changed:
107 reload_config()
108
109
110 def validate_theme(theme):
111 """
112 Validate a theme exists or not
113 """
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
118
119
120 def reload_theme(value, prev):
121 """
122 Check current theme and update if necessary
123 """
124 if value != prev:
125 config = os.path.dirname(
126 __file__) + '/colorset/' + value + '.json'
127 # Load new config
128 data = load_config(config)
129 if data:
130 for d in data:
131 c[d] = data[d]
132 # Restart color cycle and update config
133 start_cycle()
134 set_config('THEME', value)
135 return value
136 return prev
137
138
139 def color_func(func_name):
140 """
141 Call color function base on name
142 """
143 if str(func_name).isdigit():
144 return term_color(int(func_name))
145 return globals()[func_name]
146
147
148 def draw(t, keyword=None, humanize=True, fil=[], ig=[]):
149 """
150 Draw the rainbow
151 """
152 # Check config
153 check_config()
154
155 # Retrieve tweet
156 tid = t['id']
157 text = t['text']
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')
166 if humanize:
167 lang, encode = locale.getdefaultlocale()
168 clock = arrow.get(date).to('local').humanize(locale=lang)
169 else:
170 try:
171 clock_format = c['FORMAT']['TWEET']['CLOCK_FORMAT']
172 except:
173 clock_format = '%Y/%m/%d %H:%M:%S'
174 clock = date.datetime.strftime(clock_format)
175
176 # Pull extended retweet text
177 try:
178 text = 'RT @' + t['retweeted_status']['user']['screen_name'] + ': ' +\
179 t['retweeted_status']['text']
180 except:
181 pass
182
183 # Unescape HTML character
184 text = unescape(text)
185
186 # Get expanded url
187 try:
188 expanded_url = []
189 url = []
190 urls = t['entities']['urls']
191 for u in urls:
192 expanded_url.append(u['expanded_url'])
193 url.append(u['url'])
194 except:
195 expanded_url = None
196 url = None
197
198 # Get media
199 try:
200 media_url = []
201 media = t['entities']['media']
202 for m in media:
203 media_url.append(m['media_url'])
204 except:
205 media_url = None
206
207 # Filter and ignore
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:
213 return
214 if ig and screen_name in ig:
215 return
216
217 # Get rainbow id
218 if tid not in c['tweet_dict']:
219 c['tweet_dict'].append(tid)
220 rid = len(c['tweet_dict']) - 1
221 else:
222 rid = c['tweet_dict'].index(tid)
223
224 # Format info
225 name = cycle_color(name)
226 if mytweet:
227 nick = color_func(c['TWEET']['mynick'])(screen_name)
228 else:
229 nick = color_func(c['TWEET']['nick'])(screen_name)
230 clock = clock
231 id = str(rid)
232 fav = ''
233 if favorited:
234 fav = color_func(c['TWEET']['favorited'])(u'\u2605')
235
236 tweet = text.split()
237 # Replace url
238 if expanded_url:
239 for index in xrange(len(expanded_url)):
240 tweet = lmap(
241 lambda x: expanded_url[index]
242 if x == url[index]
243 else x,
244 tweet)
245 # Highlight RT
246 tweet = lmap(
247 lambda x: color_func(c['TWEET']['rt'])(x)
248 if x == 'RT'
249 else x,
250 tweet)
251 # Highlight screen_name
252 tweet = lmap(lambda x: cycle_color(x) if x[0] == '@' else x, tweet)
253 # Highlight link
254 tweet = lmap(
255 lambda x: color_func(c['TWEET']['link'])(x)
256 if x.startswith('http')
257 else x,
258 tweet)
259 # Highlight hashtag
260 tweet = lmap(
261 lambda x: color_func(c['TWEET']['hashtag'])(x)
262 if x.startswith('#')
263 else x,
264 tweet)
265 # Highlight my tweet
266 if mytweet:
267 tweet = [color_func(c['TWEET']['mytweet'])(x)
268 for x in tweet
269 if not any([
270 x == 'RT',
271 x.startswith('http'),
272 x.startswith('#')])
273 ]
274 # Highlight keyword
275 tweet = ' '.join(tweet)
276 if keyword:
277 roj = re.search(keyword, tweet, re.IGNORECASE)
278 if roj:
279 occur = roj.group()
280 ary = tweet.split(occur)
281 delimiter = color_func(c['TWEET']['keyword'])(occur)
282 tweet = delimiter.join(ary)
283
284 # Load config formater
285 formater = ''
286 try:
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'))
292 # Change clock word
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))
297 # Change id 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))
311 except:
312 pass
313
314 # Draw
315 printNicely(formater)
316
317 # Display Image
318 if c['IMAGE_ON_TERM'] and media_url:
319 for mu in media_url:
320 try:
321 response = requests.get(mu)
322 image_to_display(BytesIO(response.content))
323 except Exception:
324 printNicely(red('Sorry, image link is broken'))
325
326
327 def print_threads(d):
328 """
329 Print threads of messages
330 """
331 id = 1
332 rel = {}
333 for partner in d:
334 messages = d[partner]
335 count = len(messages)
336 screen_name = '@' + partner[0]
337 name = partner[1]
338 screen_name = color_func(c['MESSAGE']['partner'])(screen_name)
339 name = cycle_color(name)
340 thread_id = color_func(c['MESSAGE']['id'])('thread_id:' + str(id))
341 line = ' ' * 2 + name + ' ' + screen_name + \
342 ' (' + str(count) + ' message) ' + thread_id
343 printNicely(line)
344 rel[id] = partner
345 id += 1
346 dg['thread'] = d
347 return rel
348
349
350 def print_thread(partner, me_nick, me_name):
351 """
352 Print a thread of messages
353 """
354 # Sort messages by time
355 messages = dg['thread'][partner]
356 messages.sort(key=lambda x: parser.parse(x['created_at']))
357 # Use legacy display on non-ascii text message
358 ms = [m['text'] for m in messages]
359 ums = [m for m in ms if not all(ord(c) < 128 for c in m)]
360 if ums:
361 for m in messages:
362 print_message(m)
363 printNicely('')
364 return
365 # Print the first line
366 dg['frame_margin'] = margin = 2
367 partner_nick = partner[0]
368 partner_name = partner[1]
369 left_size = len(partner_nick) + len(partner_name) + 2
370 right_size = len(me_nick) + len(me_name) + 2
371 partner_nick = color_func(c['MESSAGE']['partner'])('@' + partner_nick)
372 partner_name = cycle_color(partner_name)
373 me_screen_name = color_func(c['MESSAGE']['me'])('@' + me_nick)
374 me_name = cycle_color(me_name)
375 left = ' ' * margin + partner_name + ' ' + partner_nick
376 right = me_name + ' ' + me_screen_name + ' ' * margin
377 h, w = os.popen('stty size', 'r').read().split()
378 w = int(w)
379 line = '{}{}{}'.format(
380 left, ' ' * (w - left_size - right_size - 2 * margin), right)
381 printNicely('')
382 printNicely(line)
383 printNicely('')
384 # Print messages
385 for m in messages:
386 if m['sender_screen_name'] == me_nick:
387 print_right_message(m)
388 elif m['recipient_screen_name'] == me_nick:
389 print_left_message(m)
390
391
392 def print_right_message(m):
393 """
394 Print a message on the right of screen
395 """
396 h, w = os.popen('stty size', 'r').read().split()
397 w = int(w)
398 frame_width = w // 3 - dg['frame_margin']
399 frame_width = max(c['THREAD_MIN_WIDTH'], frame_width)
400 step = frame_width - 2 * dg['frame_margin']
401 slicing = textwrap.wrap(m['text'], step)
402 spaces = w - frame_width - dg['frame_margin']
403 dotline = ' ' * spaces + '-' * frame_width
404 dotline = color_func(c['MESSAGE']['me_frame'])(dotline)
405 # Draw the frame
406 printNicely(dotline)
407 for line in slicing:
408 fill = step - len(line)
409 screen_line = ' ' * spaces + '| ' + line + ' ' * fill + ' '
410 if slicing[-1] == line:
411 screen_line = screen_line + ' >'
412 else:
413 screen_line = screen_line + '|'
414 screen_line = color_func(c['MESSAGE']['me_frame'])(screen_line)
415 printNicely(screen_line)
416 printNicely(dotline)
417 # Format clock
418 date = parser.parse(m['created_at'])
419 date = arrow.get(date).to('local').datetime
420 clock_format = '%Y/%m/%d %H:%M:%S'
421 try:
422 clock_format = c['FORMAT']['MESSAGE']['CLOCK_FORMAT']
423 except:
424 pass
425 clock = date.strftime(clock_format)
426 # Format id
427 if m['id'] not in c['message_dict']:
428 c['message_dict'].append(m['id'])
429 rid = len(c['message_dict']) - 1
430 else:
431 rid = c['message_dict'].index(m['id'])
432 id = str(rid)
433 # Print meta
434 formater = ''
435 try:
436 virtual_meta = formater = c['THREAD_META_RIGHT']
437 virtual_meta = clock.join(virtual_meta.split('#clock'))
438 virtual_meta = id.join(virtual_meta.split('#id'))
439 # Change clock word
440 word = [wo for wo in formater.split() if '#clock' in wo][0]
441 delimiter = color_func(c['MESSAGE']['clock'])(
442 clock.join(word.split('#clock')))
443 formater = delimiter.join(formater.split(word))
444 # Change id word
445 word = [wo for wo in formater.split() if '#id' in wo][0]
446 delimiter = color_func(c['MESSAGE']['id'])(id.join(word.split('#id')))
447 formater = delimiter.join(formater.split(word))
448 except Exception:
449 printNicely(red('Wrong format in config.'))
450 return
451 meta = formater
452 line = ' ' * (w - len(virtual_meta) - dg['frame_margin']) + meta
453 printNicely(line)
454
455
456 def print_left_message(m):
457 """
458 Print a message on the left of screen
459 """
460 h, w = os.popen('stty size', 'r').read().split()
461 w = int(w)
462 frame_width = w // 3 - dg['frame_margin']
463 frame_width = max(c['THREAD_MIN_WIDTH'], frame_width)
464 step = frame_width - 2 * dg['frame_margin']
465 slicing = textwrap.wrap(m['text'], step)
466 spaces = dg['frame_margin']
467 dotline = ' ' * spaces + '-' * frame_width
468 dotline = color_func(c['MESSAGE']['partner_frame'])(dotline)
469 # Draw the frame
470 printNicely(dotline)
471 for line in slicing:
472 fill = step - len(line)
473 screen_line = ' ' + line + ' ' * fill + ' |'
474 if slicing[-1] == line:
475 screen_line = ' ' * (spaces - 1) + '< ' + screen_line
476 else:
477 screen_line = ' ' * spaces + '|' + screen_line
478 screen_line = color_func(c['MESSAGE']['partner_frame'])(screen_line)
479 printNicely(screen_line)
480 printNicely(dotline)
481 # Format clock
482 date = parser.parse(m['created_at'])
483 date = arrow.get(date).to('local').datetime
484 clock_format = '%Y/%m/%d %H:%M:%S'
485 try:
486 clock_format = c['FORMAT']['MESSAGE']['CLOCK_FORMAT']
487 except:
488 pass
489 clock = date.strftime(clock_format)
490 # Format id
491 if m['id'] not in c['message_dict']:
492 c['message_dict'].append(m['id'])
493 rid = len(c['message_dict']) - 1
494 else:
495 rid = c['message_dict'].index(m['id'])
496 id = str(rid)
497 # Print meta
498 formater = ''
499 try:
500 virtual_meta = formater = c['THREAD_META_LEFT']
501 virtual_meta = clock.join(virtual_meta.split('#clock'))
502 virtual_meta = id.join(virtual_meta.split('#id'))
503 # Change clock word
504 word = [wo for wo in formater.split() if '#clock' in wo][0]
505 delimiter = color_func(c['MESSAGE']['clock'])(
506 clock.join(word.split('#clock')))
507 formater = delimiter.join(formater.split(word))
508 # Change id word
509 word = [wo for wo in formater.split() if '#id' in wo][0]
510 delimiter = color_func(c['MESSAGE']['id'])(id.join(word.split('#id')))
511 formater = delimiter.join(formater.split(word))
512 except Exception:
513 printNicely(red('Wrong format in config.'))
514 return
515 meta = formater
516 line = ' ' * dg['frame_margin'] + meta
517 printNicely(line)
518
519
520 def print_message(m):
521 """
522 Print direct message
523 """
524 # Retrieve message
525 sender_screen_name = '@' + m['sender_screen_name']
526 sender_name = m['sender']['name']
527 text = unescape(m['text'])
528 recipient_screen_name = '@' + m['recipient_screen_name']
529 recipient_name = m['recipient']['name']
530 mid = m['id']
531 date = parser.parse(m['created_at'])
532 date = arrow.get(date).to('local').datetime
533 clock_format = '%Y/%m/%d %H:%M:%S'
534 try:
535 clock_format = c['FORMAT']['MESSAGE']['CLOCK_FORMAT']
536 except:
537 pass
538 clock = date.strftime(clock_format)
539
540 # Get rainbow id
541 if mid not in c['message_dict']:
542 c['message_dict'].append(mid)
543 rid = len(c['message_dict']) - 1
544 else:
545 rid = c['message_dict'].index(mid)
546
547 # Draw
548 sender_name = cycle_color(sender_name)
549 sender_nick = color_func(c['MESSAGE']['sender'])(sender_screen_name)
550 recipient_name = cycle_color(recipient_name)
551 recipient_nick = color_func(
552 c['MESSAGE']['recipient'])(recipient_screen_name)
553 to = color_func(c['MESSAGE']['to'])('>>>')
554 clock = clock
555 id = str(rid)
556
557 text = ''.join(lmap(lambda x: x + ' ' if x == '\n' else x, text))
558
559 # Load config formater
560 try:
561 formater = c['FORMAT']['MESSAGE']['DISPLAY']
562 formater = sender_name.join(formater.split("#sender_name"))
563 formater = sender_nick.join(formater.split("#sender_nick"))
564 formater = to.join(formater.split("#to"))
565 formater = recipient_name.join(formater.split("#recipient_name"))
566 formater = recipient_nick.join(formater.split("#recipient_nick"))
567 formater = text.join(formater.split("#message"))
568 # Change clock word
569 word = [wo for wo in formater.split() if '#clock' in wo][0]
570 delimiter = color_func(c['MESSAGE']['clock'])(
571 clock.join(word.split('#clock')))
572 formater = delimiter.join(formater.split(word))
573 # Change id word
574 word = [wo for wo in formater.split() if '#id' in wo][0]
575 delimiter = color_func(c['MESSAGE']['id'])(id.join(word.split('#id')))
576 formater = delimiter.join(formater.split(word))
577 except:
578 printNicely(red('Wrong format in config.'))
579 return
580
581 # Draw
582 printNicely(formater)
583
584
585 def show_profile(u):
586 """
587 Show a profile
588 """
589 # Retrieve info
590 name = u['name']
591 screen_name = u['screen_name']
592 description = u['description']
593 profile_image_url = u['profile_image_url']
594 location = u['location']
595 url = u['url']
596 created_at = u['created_at']
597 statuses_count = u['statuses_count']
598 friends_count = u['friends_count']
599 followers_count = u['followers_count']
600
601 # Create content
602 statuses_count = color_func(
603 c['PROFILE']['statuses_count'])(
604 str(statuses_count) +
605 ' tweets')
606 friends_count = color_func(
607 c['PROFILE']['friends_count'])(
608 str(friends_count) +
609 ' following')
610 followers_count = color_func(
611 c['PROFILE']['followers_count'])(
612 str(followers_count) +
613 ' followers')
614 count = statuses_count + ' ' + friends_count + ' ' + followers_count
615 user = cycle_color(
616 name) + color_func(c['PROFILE']['nick'])(' @' + screen_name + ' : ') + count
617 profile_image_raw_url = 'Profile photo: ' + \
618 color_func(c['PROFILE']['profile_image_url'])(profile_image_url)
619 description = ''.join(
620 lmap(lambda x: x + ' ' * 4 if x == '\n' else x, description))
621 description = color_func(c['PROFILE']['description'])(description)
622 location = 'Location : ' + color_func(c['PROFILE']['location'])(location)
623 url = 'URL : ' + (color_func(c['PROFILE']['url'])(url) if url else '')
624 date = parser.parse(created_at)
625 lang, encode = locale.getdefaultlocale()
626 clock = arrow.get(date).to('local').humanize(locale=lang)
627 clock = 'Join at ' + color_func(c['PROFILE']['clock'])(clock)
628
629 # Format
630 line1 = u"{u:>{uw}}".format(
631 u=user,
632 uw=len(user) + 2,
633 )
634 line2 = u"{p:>{pw}}".format(
635 p=profile_image_raw_url,
636 pw=len(profile_image_raw_url) + 4,
637 )
638 line3 = u"{d:>{dw}}".format(
639 d=description,
640 dw=len(description) + 4,
641 )
642 line4 = u"{l:>{lw}}".format(
643 l=location,
644 lw=len(location) + 4,
645 )
646 line5 = u"{u:>{uw}}".format(
647 u=url,
648 uw=len(url) + 4,
649 )
650 line6 = u"{c:>{cw}}".format(
651 c=clock,
652 cw=len(clock) + 4,
653 )
654
655 # Display
656 printNicely('')
657 printNicely(line1)
658 if c['IMAGE_ON_TERM']:
659 try:
660 response = requests.get(profile_image_url)
661 image_to_display(BytesIO(response.content))
662 except:
663 pass
664 else:
665 printNicely(line2)
666 for line in [line3, line4, line5, line6]:
667 printNicely(line)
668 printNicely('')
669
670
671 def print_trends(trends):
672 """
673 Display topics
674 """
675 for topic in trends[:c['TREND_MAX']]:
676 name = topic['name']
677 url = topic['url']
678 line = cycle_color(name) + ': ' + color_func(c['TREND']['url'])(url)
679 printNicely(line)
680 printNicely('')
681
682
683 def print_list(group):
684 """
685 Display a list
686 """
687 for grp in group:
688 # Format
689 name = grp['full_name']
690 name = color_func(c['GROUP']['name'])(name + ' : ')
691 member = str(grp['member_count'])
692 member = color_func(c['GROUP']['member'])(member + ' member')
693 subscriber = str(grp['subscriber_count'])
694 subscriber = color_func(
695 c['GROUP']['subscriber'])(
696 subscriber +
697 ' subscriber')
698 description = grp['description'].strip()
699 description = color_func(c['GROUP']['description'])(description)
700 mode = grp['mode']
701 mode = color_func(c['GROUP']['mode'])('Type: ' + mode)
702 created_at = grp['created_at']
703 date = parser.parse(created_at)
704 lang, encode = locale.getdefaultlocale()
705 clock = arrow.get(date).to('local').humanize(locale=lang)
706 clock = 'Created at ' + color_func(c['GROUP']['clock'])(clock)
707
708 # Create lines
709 line1 = ' ' * 2 + name + member + ' ' + subscriber
710 line2 = ' ' * 4 + description
711 line3 = ' ' * 4 + mode
712 line4 = ' ' * 4 + clock
713
714 # Display
715 printNicely('')
716 printNicely(line1)
717 printNicely(line2)
718 printNicely(line3)
719 printNicely(line4)
720
721 printNicely('')
722
723
724 def show_calendar(month, date, rel):
725 """
726 Show the calendar in rainbow mode
727 """
728 month = random_rainbow(month)
729 date = ' '.join([cycle_color(i) for i in date.split(' ')])
730 today = str(int(os.popen('date +\'%d\'').read().strip()))
731 # Display
732 printNicely(month)
733 printNicely(date)
734 for line in rel:
735 ary = line.split(' ')
736 ary = lmap(
737 lambda x: color_func(c['CAL']['today'])(x)
738 if x == today
739 else color_func(c['CAL']['days'])(x),
740 ary)
741 printNicely(' '.join(ary))
742
743
744 def format_quote(tweet):
745 """
746 Quoting format
747 """
748 # Retrieve info
749 screen_name = '@' + tweet['user']['screen_name']
750 text = tweet['text']
751 # Validate quote format
752 if '#owner' not in c['QUOTE_FORMAT']:
753 printNicely(light_magenta('Quote should contains #owner'))
754 return False
755 if '#comment' not in c['QUOTE_FORMAT']:
756 printNicely(light_magenta('Quote format should have #comment'))
757 return False
758 # Build formater
759 formater = ''
760 try:
761 formater = c['QUOTE_FORMAT']
762 formater = screen_name.join(formater.split('#owner'))
763 formater = text.join(formater.split('#tweet'))
764 formater = u2str(formater)
765 except:
766 pass
767 # Highlight like a tweet
768 notice = formater.split()
769 notice = lmap(
770 lambda x: light_green(x)
771 if x == '#comment'
772 else x,
773 notice)
774 notice = lmap(
775 lambda x: color_func(c['TWEET']['rt'])(x)
776 if x == 'RT'
777 else x,
778 notice)
779 notice = lmap(lambda x: cycle_color(x) if x[0] == '@' else x, notice)
780 notice = lmap(
781 lambda x: color_func(c['TWEET']['link'])(x)
782 if x[0:4] == 'http'
783 else x,
784 notice)
785 notice = lmap(
786 lambda x: color_func(c['TWEET']['hashtag'])(x)
787 if x.startswith('#')
788 else x,
789 notice)
790 notice = ' '.join(notice)
791 # Notice
792 notice = light_magenta('Quoting: "') + notice + light_magenta('"')
793 printNicely(notice)
794 return formater
795
796
797 # Start the color cycle
798 start_cycle()