7 from twitter
.util
import printNicely
8 from functools
import wraps
9 from pyfiglet
import figlet_format
10 from dateutil
import parser
11 from .c_image
import *
15 from .py3patch
import *
26 colors_shuffle
= [globals()[i
.encode('utf8')]
27 if not str(i
).isdigit()
28 else term_color(int(i
))
29 for i
in c
['CYCLE_COLOR']]
30 return itertools
.cycle(colors_shuffle
)
31 g
['cyc'] = init_cycle()
39 g
['cyc'] = init_cycle()
45 Print a string with ordered color with each character
47 colors_shuffle
= [globals()[i
.encode('utf8')]
48 if not str(i
).isdigit()
49 else term_color(int(i
))
50 for i
in c
['CYCLE_COLOR']]
51 colored
= [colors_shuffle
[i
% 7](s
[i
]) for i
in xrange(len(s
))]
52 return ''.join(colored
)
55 def random_rainbow(s
):
57 Print a string with random color with each character
59 colors_shuffle
= [globals()[i
.encode('utf8')]
60 if not str(i
).isdigit()
61 else term_color(int(i
))
62 for i
in c
['CYCLE_COLOR']]
63 colored
= [random
.choice(colors_shuffle
)(i
) for i
in s
]
64 return ''.join(colored
)
73 if args
not in g
['cache']:
74 g
['cache'][args
] = func(*args
)
75 return g
['cache'][args
]
82 Cycle the colors_shuffle
84 return next(g
['cyc'])(s
)
91 fi
= figlet_format(text
, font
='doom')
93 [next(g
['cyc'])(i
) for i
in fi
.split('\n')]
97 def show_calendar(month
, date
, rel
):
99 Show the calendar in rainbow mode
101 month
= random_rainbow(month
)
102 date
= ' '.join([cycle_color(i
) for i
in date
.split(' ')])
103 today
= str(int(os
.popen('date +\'%d\'').read().strip()))
108 ary
= line
.split(' ')
109 ary
= lmap(lambda x
: color_func(c
['CAL']['today'])(x
)
111 else color_func(c
['CAL']['days'])(x
), ary
)
112 printNicely(' '.join(ary
))
117 Check current theme and update if necessary
119 exists
= db
.theme_query()
120 themes
= [t
.theme_name
for t
in exists
]
121 if c
['THEME'] != themes
[0]:
122 c
['THEME'] = themes
[0]
123 config
= os
.path
.dirname(
124 __file__
) + '/colorset/' + c
['THEME'] + '.json'
126 data
= load_config(config
)
130 # Re-init color cycle
131 g
['cyc'] = init_cycle()
134 def color_func(func_name
):
136 Call color function base on name
138 if str(func_name
).isdigit():
139 return term_color(int(func_name
))
140 return globals()[func_name
]
143 def draw(t
, iot
=False, keyword
=None, fil
=[], ig
=[]):
152 screen_name
= t
['user']['screen_name']
153 name
= t
['user']['name']
154 created_at
= t
['created_at']
155 favorited
= t
['favorited']
156 date
= parser
.parse(created_at
)
157 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
158 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
164 urls
= t
['entities']['urls']
166 expanded_url
.append(u
['expanded_url'])
175 media
= t
['entities']['media']
177 media_url
.append(m
['media_url'])
182 screen_name
= '@' + screen_name
183 if fil
and screen_name
not in fil
:
185 if ig
and screen_name
in ig
:
189 res
= db
.tweet_to_rainbow_query(tid
)
192 res
= db
.tweet_to_rainbow_query(tid
)
193 rid
= res
[0].rainbow_id
197 name
) + color_func(c
['TWEET']['nick'])(' ' + screen_name
+ ' ')
198 meta
= color_func(c
['TWEET']['clock'])(
199 '[' + clock
+ '] ') + color_func(c
['TWEET']['id'])('[id=' + str(rid
) + '] ')
201 meta
= meta
+ color_func(c
['TWEET']['favorited'])(u
'\u2605')
205 for index
in range(len(expanded_url
)):
207 lambda x
: expanded_url
[index
] if x
== url
[index
] else x
,
211 lambda x
: color_func(
212 c
['TWEET']['rt'])(x
) if x
== 'RT' else x
,
214 # Highlight screen_name
215 tweet
= lmap(lambda x
: cycle_color(x
) if x
[0] == '@' else x
, tweet
)
218 lambda x
: color_func(
219 c
['TWEET']['link'])(x
) if x
[
220 0:4] == 'http' else x
,
222 # Highlight search keyword
225 lambda x
: color_func(c
['TWEET']['keyword'])(x
) if
226 ''.join(c
for c
in x
if c
.isalnum()).lower() == keyword
.lower()
231 tweet
= ' '.join(tweet
)
234 line1
= u
"{u:>{uw}}:".format(
238 line2
= u
"{c:>{cw}}".format(
250 if iot
and media_url
:
253 response
= requests
.get(mu
)
254 image_to_display(BytesIO(response
.content
))
256 printNicely(red('Sorry, image link is broken'))
259 def print_message(m
):
263 sender_screen_name
= '@' + m
['sender_screen_name']
264 sender_name
= m
['sender']['name']
266 recipient_screen_name
= '@' + m
['recipient_screen_name']
267 recipient_name
= m
['recipient']['name']
269 date
= parser
.parse(m
['created_at'])
270 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
271 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
274 res
= db
.message_to_rainbow_query(mid
)
276 db
.message_store(mid
)
277 res
= db
.message_to_rainbow_query(mid
)
278 rid
= res
[0].rainbow_id
281 sender
= cycle_color(
282 sender_name
) + color_func(c
['MESSAGE']['sender'])(' ' + sender_screen_name
+ ' ')
283 recipient
= cycle_color(recipient_name
) + color_func(
284 c
['MESSAGE']['recipient'])(
285 ' ' + recipient_screen_name
+ ' ')
286 user
= sender
+ color_func(c
['MESSAGE']['to'])(' >>> ') + recipient
288 c
['MESSAGE']['clock'])(
289 '[' + clock
+ ']') + color_func(
291 ' [message_id=' + str(rid
) + '] ')
292 text
= ''.join(lmap(lambda x
: x
+ ' ' if x
== '\n' else x
, text
))
294 line1
= u
"{u:>{uw}}:".format(
298 line2
= u
"{c:>{cw}}".format(
311 def show_profile(u
, iot
=False):
317 screen_name
= u
['screen_name']
318 description
= u
['description']
319 profile_image_url
= u
['profile_image_url']
320 location
= u
['location']
322 created_at
= u
['created_at']
323 statuses_count
= u
['statuses_count']
324 friends_count
= u
['friends_count']
325 followers_count
= u
['followers_count']
328 statuses_count
= color_func(
329 c
['PROFILE']['statuses_count'])(
330 str(statuses_count
) +
332 friends_count
= color_func(
333 c
['PROFILE']['friends_count'])(
336 followers_count
= color_func(
337 c
['PROFILE']['followers_count'])(
338 str(followers_count
) +
340 count
= statuses_count
+ ' ' + friends_count
+ ' ' + followers_count
342 name
) + color_func(c
['PROFILE']['nick'])(' @' + screen_name
+ ' : ') + count
343 profile_image_raw_url
= 'Profile photo: ' + \
344 color_func(c
['PROFILE']['profile_image_url'])(profile_image_url
)
345 description
= ''.join(
346 lmap(lambda x
: x
+ ' ' * 4 if x
== '\n' else x
, description
))
347 description
= color_func(c
['PROFILE']['description'])(description
)
348 location
= 'Location : ' + color_func(c
['PROFILE']['location'])(location
)
349 url
= 'URL : ' + (color_func(c
['PROFILE']['url'])(url
) if url
else '')
350 date
= parser
.parse(created_at
)
351 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
352 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
353 clock
= 'Join at ' + color_func(c
['PROFILE']['clock'])(clock
)
356 line1
= u
"{u:>{uw}}".format(
360 line2
= u
"{p:>{pw}}".format(
361 p
=profile_image_raw_url
,
362 pw
=len(profile_image_raw_url
) + 4,
364 line3
= u
"{d:>{dw}}".format(
366 dw
=len(description
) + 4,
368 line4
= u
"{l:>{lw}}".format(
370 lw
=len(location
) + 4,
372 line5
= u
"{u:>{uw}}".format(
376 line6
= u
"{c:>{cw}}".format(
386 response
= requests
.get(profile_image_url
)
387 image_to_display(BytesIO(response
.content
), 2, 20)
392 for line
in [line3
, line4
, line5
, line6
]:
397 def print_trends(trends
):
401 for topic
in trends
[:c
['TREND_MAX']]:
404 line
= cycle_color(name
) + ': ' + color_func(c
['TREND']['url'])(url
)
409 def print_list(group
):
415 name
= g
['full_name']
416 name
= color_func(c
['GROUP']['name'])(name
+ ' : ')
417 member
= str(g
['member_count'])
418 member
= color_func(c
['GROUP']['member'])(member
+ ' member')
419 subscriber
= str(g
['subscriber_count'])
420 subscriber
= color_func(
421 c
['GROUP']['subscriber'])(
424 description
= g
['description'].strip()
425 description
= color_func(c
['GROUP']['description'])(description
)
427 mode
= color_func(c
['GROUP']['mode'])('Type: ' + mode
)
428 created_at
= g
['created_at']
429 date
= parser
.parse(created_at
)
430 date
= date
- datetime
.timedelta(seconds
=time
.timezone
)
431 clock
= date
.strftime('%Y/%m/%d %H:%M:%S')
432 clock
= 'Created at ' + color_func(c
['GROUP']['clock'])(clock
)
435 line1
= ' ' * 2 + name
+ member
+ ' ' + subscriber
436 line2
= ' ' * 4 + description
437 line3
= ' ' * 4 + mode
438 line4
= ' ' * 4 + clock