9f8a0eb9adcf5c3dda181d1d804d813a2717166b
[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 screen_name = '@' + screen_name
209 fil = list(set((fil or []) + c['ONLY_LIST']))
210 ig = list(set((ig or []) + c['IGNORE_LIST']))
211 if fil and screen_name not in fil:
212 return
213 if ig and screen_name in ig:
214 return
215
216 # Get rainbow id
217 if tid not in c['tweet_dict']:
218 c['tweet_dict'].append(tid)
219 rid = len(c['tweet_dict']) - 1
220 else:
221 rid = c['tweet_dict'].index(tid)
222
223 # Format info
224 name = cycle_color(name)
225 nick = color_func(c['TWEET']['nick'])(screen_name)
226 clock = clock
227 id = str(rid)
228 fav = ''
229 if favorited:
230 fav = color_func(c['TWEET']['favorited'])(u'\u2605')
231
232 tweet = text.split()
233 # Replace url
234 if expanded_url:
235 for index in xrange(len(expanded_url)):
236 tweet = lmap(
237 lambda x: expanded_url[index]
238 if x == url[index]
239 else x,
240 tweet)
241 # Highlight RT
242 tweet = lmap(
243 lambda x: color_func(c['TWEET']['rt'])(x)
244 if x == 'RT'
245 else x,
246 tweet)
247 # Highlight screen_name
248 tweet = lmap(lambda x: cycle_color(x) if x[0] == '@' else x, tweet)
249 # Highlight link
250 tweet = lmap(
251 lambda x: color_func(c['TWEET']['link'])(x)
252 if x[0:4] == 'http'
253 else x,
254 tweet)
255 # Highlight hashtag
256 tweet = lmap(
257 lambda x: color_func(c['TWEET']['hashtag'])(x)
258 if x.startswith('#')
259 else x,
260 tweet)
261 # Highlight keyword
262 tweet = ' '.join(tweet)
263 if keyword:
264 roj = re.search(keyword, tweet, re.IGNORECASE)
265 if roj:
266 occur = roj.group()
267 ary = tweet.split(occur)
268 delimiter = color_func(c['TWEET']['keyword'])(occur)
269 tweet = delimiter.join(ary)
270
271 # Load config formater
272 formater = ''
273 try:
274 formater = c['FORMAT']['TWEET']['DISPLAY']
275 formater = name.join(formater.split('#name'))
276 formater = nick.join(formater.split('#nick'))
277 formater = fav.join(formater.split('#fav'))
278 formater = tweet.join(formater.split('#tweet'))
279 # Change clock word
280 word = [wo for wo in formater.split() if '#clock' in wo][0]
281 delimiter = color_func(c['TWEET']['clock'])(
282 clock.join(word.split('#clock')))
283 formater = delimiter.join(formater.split(word))
284 # Change id word
285 word = [wo for wo in formater.split() if '#id' in wo][0]
286 delimiter = color_func(c['TWEET']['id'])(id.join(word.split('#id')))
287 formater = delimiter.join(formater.split(word))
288 # Change retweet count word
289 word = [wo for wo in formater.split() if '#rt_count' in wo][0]
290 delimiter = color_func(c['TWEET']['retweet_count'])(
291 str(retweet_count).join(word.split('#rt_count')))
292 formater = delimiter.join(formater.split(word))
293 # Change favorites count word
294 word = [wo for wo in formater.split() if '#fa_count' in wo][0]
295 delimiter = color_func(c['TWEET']['favorite_count'])(
296 str(favorite_count).join(word.split('#fa_count')))
297 formater = delimiter.join(formater.split(word))
298 except:
299 pass
300
301 # Draw
302 printNicely(formater)
303
304 # Display Image
305 if c['IMAGE_ON_TERM'] and media_url:
306 for mu in media_url:
307 try:
308 response = requests.get(mu)
309 image_to_display(BytesIO(response.content))
310 except Exception:
311 printNicely(red('Sorry, image link is broken'))
312
313
314 def print_threads(d):
315 """
316 Print threads of messages
317 """
318 id = 1
319 rel = {}
320 for partner in d:
321 messages = d[partner]
322 count = len(messages)
323 screen_name = '@' + partner[0]
324 name = partner[1]
325 screen_name = color_func(c['MESSAGE']['partner'])(screen_name)
326 name = cycle_color(name)
327 thread_id = color_func(c['MESSAGE']['id'])('thread_id:' + str(id))
328 line = ' ' * 2 + name + ' ' + screen_name + \
329 ' (' + str(count) + ' message) ' + thread_id
330 printNicely(line)
331 rel[id] = partner
332 id += 1
333 dg['thread'] = d
334 return rel
335
336
337 def print_thread(partner, me_nick, me_name):
338 """
339 Print a thread of messages
340 """
341 # Sort messages by time
342 messages = dg['thread'][partner]
343 messages.sort(key=lambda x: parser.parse(x['created_at']))
344 # Use legacy display on non-ascii text message
345 ms = [m['text'] for m in messages]
346 ums = [m for m in ms if not all(ord(c) < 128 for c in m)]
347 if ums:
348 for m in messages:
349 print_message(m)
350 printNicely('')
351 return
352 # Print the first line
353 dg['frame_margin'] = margin = 2
354 partner_nick = partner[0]
355 partner_name = partner[1]
356 left_size = len(partner_nick) + len(partner_name) + 2
357 right_size = len(me_nick) + len(me_name) + 2
358 partner_nick = color_func(c['MESSAGE']['partner'])('@' + partner_nick)
359 partner_name = cycle_color(partner_name)
360 me_screen_name = color_func(c['MESSAGE']['me'])('@' + me_nick)
361 me_name = cycle_color(me_name)
362 left = ' ' * margin + partner_name + ' ' + partner_nick
363 right = me_name + ' ' + me_screen_name + ' ' * margin
364 h, w = os.popen('stty size', 'r').read().split()
365 w = int(w)
366 line = '{}{}{}'.format(
367 left, ' ' * (w - left_size - right_size - 2 * margin), right)
368 printNicely('')
369 printNicely(line)
370 printNicely('')
371 # Print messages
372 for m in messages:
373 if m['sender_screen_name'] == me_nick:
374 print_right_message(m)
375 elif m['recipient_screen_name'] == me_nick:
376 print_left_message(m)
377
378
379 def print_right_message(m):
380 """
381 Print a message on the right of screen
382 """
383 h, w = os.popen('stty size', 'r').read().split()
384 w = int(w)
385 frame_width = w // 3 - dg['frame_margin']
386 step = frame_width - 2 * dg['frame_margin']
387 slicing = textwrap.wrap(m['text'], step)
388 spaces = w - frame_width - dg['frame_margin']
389 dotline = ' ' * spaces + '-' * frame_width
390 dotline = color_func(c['MESSAGE']['me_frame'])(dotline)
391 # Draw the frame
392 printNicely(dotline)
393 for line in slicing:
394 fill = step - len(line)
395 screen_line = ' ' * spaces + '| ' + line + ' ' * fill + ' '
396 if slicing[-1] == line:
397 screen_line = screen_line + ' >'
398 else:
399 screen_line = screen_line + '|'
400 screen_line = color_func(c['MESSAGE']['me_frame'])(screen_line)
401 printNicely(screen_line)
402 printNicely(dotline)
403 # Format clock
404 date = parser.parse(m['created_at'])
405 date = arrow.get(date).to('local').datetime
406 clock_format = '%Y/%m/%d %H:%M:%S'
407 try:
408 clock_format = c['FORMAT']['MESSAGE']['CLOCK_FORMAT']
409 except:
410 pass
411 clock = date.strftime(clock_format)
412 # Format id
413 if m['id'] not in c['message_dict']:
414 c['message_dict'].append(m['id'])
415 rid = len(c['message_dict']) - 1
416 else:
417 rid = c['message_dict'].index(m['id'])
418 id = str(rid)
419 # Print meta
420 formater = ''
421 try:
422 virtual_meta = formater = c['THREAD_META_RIGHT']
423 virtual_meta = clock.join(virtual_meta.split('#clock'))
424 virtual_meta = id.join(virtual_meta.split('#id'))
425 # Change clock word
426 word = [wo for wo in formater.split() if '#clock' in wo][0]
427 delimiter = color_func(c['MESSAGE']['clock'])(
428 clock.join(word.split('#clock')))
429 formater = delimiter.join(formater.split(word))
430 # Change id word
431 word = [wo for wo in formater.split() if '#id' in wo][0]
432 delimiter = color_func(c['MESSAGE']['id'])(id.join(word.split('#id')))
433 formater = delimiter.join(formater.split(word))
434 except Exception:
435 printNicely(red('Wrong format in config.'))
436 return
437 meta = formater
438 line = ' ' * (w - len(virtual_meta) - dg['frame_margin']) + meta
439 printNicely(line)
440
441
442 def print_left_message(m):
443 """
444 Print a message on the left of screen
445 """
446 h, w = os.popen('stty size', 'r').read().split()
447 w = int(w)
448 frame_width = w // 3 - dg['frame_margin']
449 step = frame_width - 2 * dg['frame_margin']
450 slicing = textwrap.wrap(m['text'], step)
451 spaces = dg['frame_margin']
452 dotline = ' ' * spaces + '-' * frame_width
453 dotline = color_func(c['MESSAGE']['partner_frame'])(dotline)
454 # Draw the frame
455 printNicely(dotline)
456 for line in slicing:
457 fill = step - len(line)
458 screen_line = ' ' + line + ' ' * fill + ' |'
459 if slicing[-1] == line:
460 screen_line = ' ' * (spaces - 1) + '< ' + screen_line
461 else:
462 screen_line = ' ' * spaces + '|' + screen_line
463 screen_line = color_func(c['MESSAGE']['partner_frame'])(screen_line)
464 printNicely(screen_line)
465 printNicely(dotline)
466 # Format clock
467 date = parser.parse(m['created_at'])
468 date = arrow.get(date).to('local').datetime
469 clock_format = '%Y/%m/%d %H:%M:%S'
470 try:
471 clock_format = c['FORMAT']['MESSAGE']['CLOCK_FORMAT']
472 except:
473 pass
474 clock = date.strftime(clock_format)
475 # Format id
476 if m['id'] not in c['message_dict']:
477 c['message_dict'].append(m['id'])
478 rid = len(c['message_dict']) - 1
479 else:
480 rid = c['message_dict'].index(m['id'])
481 id = str(rid)
482 # Print meta
483 formater = ''
484 try:
485 virtual_meta = formater = c['THREAD_META_LEFT']
486 virtual_meta = clock.join(virtual_meta.split('#clock'))
487 virtual_meta = id.join(virtual_meta.split('#id'))
488 # Change clock word
489 word = [wo for wo in formater.split() if '#clock' in wo][0]
490 delimiter = color_func(c['MESSAGE']['clock'])(
491 clock.join(word.split('#clock')))
492 formater = delimiter.join(formater.split(word))
493 # Change id word
494 word = [wo for wo in formater.split() if '#id' in wo][0]
495 delimiter = color_func(c['MESSAGE']['id'])(id.join(word.split('#id')))
496 formater = delimiter.join(formater.split(word))
497 except Exception:
498 printNicely(red('Wrong format in config.'))
499 return
500 meta = formater
501 line = ' ' * dg['frame_margin'] + meta
502 printNicely(line)
503
504
505 def print_message(m):
506 """
507 Print direct message
508 """
509 # Retrieve message
510 sender_screen_name = '@' + m['sender_screen_name']
511 sender_name = m['sender']['name']
512 text = unescape(m['text'])
513 recipient_screen_name = '@' + m['recipient_screen_name']
514 recipient_name = m['recipient']['name']
515 mid = m['id']
516 date = parser.parse(m['created_at'])
517 date = arrow.get(date).to('local').datetime
518 clock_format = '%Y/%m/%d %H:%M:%S'
519 try:
520 clock_format = c['FORMAT']['MESSAGE']['CLOCK_FORMAT']
521 except:
522 pass
523 clock = date.strftime(clock_format)
524
525 # Get rainbow id
526 if mid not in c['message_dict']:
527 c['message_dict'].append(mid)
528 rid = len(c['message_dict']) - 1
529 else:
530 rid = c['message_dict'].index(mid)
531
532 # Draw
533 sender_name = cycle_color(sender_name)
534 sender_nick = color_func(c['MESSAGE']['sender'])(sender_screen_name)
535 recipient_name = cycle_color(recipient_name)
536 recipient_nick = color_func(
537 c['MESSAGE']['recipient'])(recipient_screen_name)
538 to = color_func(c['MESSAGE']['to'])('>>>')
539 clock = clock
540 id = str(rid)
541
542 text = ''.join(lmap(lambda x: x + ' ' if x == '\n' else x, text))
543
544 # Load config formater
545 try:
546 formater = c['FORMAT']['MESSAGE']['DISPLAY']
547 formater = sender_name.join(formater.split("#sender_name"))
548 formater = sender_nick.join(formater.split("#sender_nick"))
549 formater = to.join(formater.split("#to"))
550 formater = recipient_name.join(formater.split("#recipient_name"))
551 formater = recipient_nick.join(formater.split("#recipient_nick"))
552 formater = text.join(formater.split("#message"))
553 # Change clock word
554 word = [wo for wo in formater.split() if '#clock' in wo][0]
555 delimiter = color_func(c['MESSAGE']['clock'])(
556 clock.join(word.split('#clock')))
557 formater = delimiter.join(formater.split(word))
558 # Change id word
559 word = [wo for wo in formater.split() if '#id' in wo][0]
560 delimiter = color_func(c['MESSAGE']['id'])(id.join(word.split('#id')))
561 formater = delimiter.join(formater.split(word))
562 except:
563 printNicely(red('Wrong format in config.'))
564 return
565
566 # Draw
567 printNicely(formater)
568
569
570 def show_profile(u):
571 """
572 Show a profile
573 """
574 # Retrieve info
575 name = u['name']
576 screen_name = u['screen_name']
577 description = u['description']
578 profile_image_url = u['profile_image_url']
579 location = u['location']
580 url = u['url']
581 created_at = u['created_at']
582 statuses_count = u['statuses_count']
583 friends_count = u['friends_count']
584 followers_count = u['followers_count']
585
586 # Create content
587 statuses_count = color_func(
588 c['PROFILE']['statuses_count'])(
589 str(statuses_count) +
590 ' tweets')
591 friends_count = color_func(
592 c['PROFILE']['friends_count'])(
593 str(friends_count) +
594 ' following')
595 followers_count = color_func(
596 c['PROFILE']['followers_count'])(
597 str(followers_count) +
598 ' followers')
599 count = statuses_count + ' ' + friends_count + ' ' + followers_count
600 user = cycle_color(
601 name) + color_func(c['PROFILE']['nick'])(' @' + screen_name + ' : ') + count
602 profile_image_raw_url = 'Profile photo: ' + \
603 color_func(c['PROFILE']['profile_image_url'])(profile_image_url)
604 description = ''.join(
605 lmap(lambda x: x + ' ' * 4 if x == '\n' else x, description))
606 description = color_func(c['PROFILE']['description'])(description)
607 location = 'Location : ' + color_func(c['PROFILE']['location'])(location)
608 url = 'URL : ' + (color_func(c['PROFILE']['url'])(url) if url else '')
609 date = parser.parse(created_at)
610 lang, encode = locale.getdefaultlocale()
611 clock = arrow.get(date).to('local').humanize(locale=lang)
612 clock = 'Join at ' + color_func(c['PROFILE']['clock'])(clock)
613
614 # Format
615 line1 = u"{u:>{uw}}".format(
616 u=user,
617 uw=len(user) + 2,
618 )
619 line2 = u"{p:>{pw}}".format(
620 p=profile_image_raw_url,
621 pw=len(profile_image_raw_url) + 4,
622 )
623 line3 = u"{d:>{dw}}".format(
624 d=description,
625 dw=len(description) + 4,
626 )
627 line4 = u"{l:>{lw}}".format(
628 l=location,
629 lw=len(location) + 4,
630 )
631 line5 = u"{u:>{uw}}".format(
632 u=url,
633 uw=len(url) + 4,
634 )
635 line6 = u"{c:>{cw}}".format(
636 c=clock,
637 cw=len(clock) + 4,
638 )
639
640 # Display
641 printNicely('')
642 printNicely(line1)
643 if c['IMAGE_ON_TERM']:
644 try:
645 response = requests.get(profile_image_url)
646 image_to_display(BytesIO(response.content))
647 except:
648 pass
649 else:
650 printNicely(line2)
651 for line in [line3, line4, line5, line6]:
652 printNicely(line)
653 printNicely('')
654
655
656 def print_trends(trends):
657 """
658 Display topics
659 """
660 for topic in trends[:c['TREND_MAX']]:
661 name = topic['name']
662 url = topic['url']
663 line = cycle_color(name) + ': ' + color_func(c['TREND']['url'])(url)
664 printNicely(line)
665 printNicely('')
666
667
668 def print_list(group):
669 """
670 Display a list
671 """
672 for grp in group:
673 # Format
674 name = grp['full_name']
675 name = color_func(c['GROUP']['name'])(name + ' : ')
676 member = str(grp['member_count'])
677 member = color_func(c['GROUP']['member'])(member + ' member')
678 subscriber = str(grp['subscriber_count'])
679 subscriber = color_func(
680 c['GROUP']['subscriber'])(
681 subscriber +
682 ' subscriber')
683 description = grp['description'].strip()
684 description = color_func(c['GROUP']['description'])(description)
685 mode = grp['mode']
686 mode = color_func(c['GROUP']['mode'])('Type: ' + mode)
687 created_at = grp['created_at']
688 date = parser.parse(created_at)
689 lang, encode = locale.getdefaultlocale()
690 clock = arrow.get(date).to('local').humanize(locale=lang)
691 clock = 'Created at ' + color_func(c['GROUP']['clock'])(clock)
692
693 # Create lines
694 line1 = ' ' * 2 + name + member + ' ' + subscriber
695 line2 = ' ' * 4 + description
696 line3 = ' ' * 4 + mode
697 line4 = ' ' * 4 + clock
698
699 # Display
700 printNicely('')
701 printNicely(line1)
702 printNicely(line2)
703 printNicely(line3)
704 printNicely(line4)
705
706 printNicely('')
707
708
709 def show_calendar(month, date, rel):
710 """
711 Show the calendar in rainbow mode
712 """
713 month = random_rainbow(month)
714 date = ' '.join([cycle_color(i) for i in date.split(' ')])
715 today = str(int(os.popen('date +\'%d\'').read().strip()))
716 # Display
717 printNicely(month)
718 printNicely(date)
719 for line in rel:
720 ary = line.split(' ')
721 ary = lmap(
722 lambda x: color_func(c['CAL']['today'])(x)
723 if x == today
724 else color_func(c['CAL']['days'])(x),
725 ary)
726 printNicely(' '.join(ary))
727
728
729 def format_quote(tweet):
730 """
731 Quoting format
732 """
733 # Retrieve info
734 screen_name = '@' + tweet['user']['screen_name']
735 text = tweet['text']
736 # Validate quote format
737 if '#owner' not in c['QUOTE_FORMAT']:
738 printNicely(light_magenta('Quote should contains #owner'))
739 return False
740 if '#comment' not in c['QUOTE_FORMAT']:
741 printNicely(light_magenta('Quote format should have #comment'))
742 return False
743 # Build formater
744 formater = ''
745 try:
746 formater = c['QUOTE_FORMAT']
747 formater = screen_name.join(formater.split('#owner'))
748 formater = text.join(formater.split('#tweet'))
749 formater = u2str(formater)
750 except:
751 pass
752 # Highlight like a tweet
753 notice = formater.split()
754 notice = lmap(
755 lambda x: light_green(x)
756 if x == '#comment'
757 else x,
758 notice)
759 notice = lmap(
760 lambda x: color_func(c['TWEET']['rt'])(x)
761 if x == 'RT'
762 else x,
763 notice)
764 notice = lmap(lambda x: cycle_color(x) if x[0] == '@' else x, notice)
765 notice = lmap(
766 lambda x: color_func(c['TWEET']['link'])(x)
767 if x[0:4] == 'http'
768 else x,
769 notice)
770 notice = lmap(
771 lambda x: color_func(c['TWEET']['hashtag'])(x)
772 if x.startswith('#')
773 else x,
774 notice)
775 notice = ' '.join(notice)
776 # Notice
777 notice = light_magenta('Quoting: "') + notice + light_magenta('"')
778 printNicely(notice)
779 return formater
780
781
782 # Start the color cycle
783 start_cycle()