import random
import itertools
import requests
-import datetime
import time
+import locale
+import arrow
import re
from twitter.util import printNicely
return globals()[func_name]
-def draw(t, keyword=None, check_semaphore=False, fil=[], ig=[]):
+def draw(t, keyword=None, humanize=True, fil=[], ig=[]):
"""
Draw the rainbow
"""
-
- # Check the semaphore pause and lock (stream process only)
- if check_semaphore:
- if c['pause']:
- return
- while c['lock']:
- time.sleep(0.5)
-
# Check config
check_config()
retweet_count = t['retweet_count']
favorite_count = t['favorite_count']
date = parser.parse(created_at)
- date = date - datetime.timedelta(seconds=time.timezone)
- clock_format = '%Y/%m/%d %H:%M:%S'
- try:
- clock_format = c['FORMAT']['TWEET']['CLOCK_FORMAT']
- except:
- pass
- clock = date.strftime(clock_format)
+ date = arrow.get(date).to('local')
+ if humanize:
+ lang, encode = locale.getdefaultlocale()
+ clock = arrow.get(date).to('local').humanize(locale=lang)
+ else:
+ try:
+ clock_format = c['FORMAT']['TWEET']['CLOCK_FORMAT']
+ except:
+ clock_format = '%Y/%m/%d %H:%M:%S'
+ clock = date.datetime.strftime(clock_format)
# Pull extended retweet text
try:
formater = ''
try:
formater = c['FORMAT']['TWEET']['DISPLAY']
- formater = name.join(formater.split("#name"))
- formater = nick.join(formater.split("#nick"))
- formater = fav.join(formater.split("#fav"))
- formater = tweet.join(formater.split("#tweet"))
+ formater = name.join(formater.split('#name'))
+ formater = nick.join(formater.split('#nick'))
+ formater = fav.join(formater.split('#fav'))
+ formater = tweet.join(formater.split('#tweet'))
# Change clock word
word = [w for w in formater.split() if '#clock' in w][0]
delimiter = color_func(c['TWEET']['clock'])(
printNicely(red('Sorry, image link is broken'))
-def print_message(m, check_semaphore=False):
+def print_message(m):
"""
Print direct message
"""
-
- # Check the semaphore pause and lock (stream process only)
- if check_semaphore:
- if c['pause']:
- return
- while c['lock']:
- time.sleep(0.5)
-
# Retrieve message
sender_screen_name = '@' + m['sender_screen_name']
sender_name = m['sender']['name']
recipient_name = m['recipient']['name']
mid = m['id']
date = parser.parse(m['created_at'])
- date = date - datetime.timedelta(seconds=time.timezone)
+ date = arrow.get(date).to('local').datetime
clock_format = '%Y/%m/%d %H:%M:%S'
try:
clock_format = c['FORMAT']['MESSAGE']['CLOCK_FORMAT']
location = 'Location : ' + color_func(c['PROFILE']['location'])(location)
url = 'URL : ' + (color_func(c['PROFILE']['url'])(url) if url else '')
date = parser.parse(created_at)
- date = date - datetime.timedelta(seconds=time.timezone)
- clock = date.strftime('%Y/%m/%d %H:%M:%S')
+ lang, encode = locale.getdefaultlocale()
+ clock = arrow.get(date).to('local').humanize(locale=lang)
clock = 'Join at ' + color_func(c['PROFILE']['clock'])(clock)
# Format
mode = color_func(c['GROUP']['mode'])('Type: ' + mode)
created_at = grp['created_at']
date = parser.parse(created_at)
- date = date - datetime.timedelta(seconds=time.timezone)
- clock = date.strftime('%Y/%m/%d %H:%M:%S')
+ lang, encode = locale.getdefaultlocale()
+ clock = arrow.get(date).to('local').humanize(locale=lang)
clock = 'Created at ' + color_func(c['GROUP']['clock'])(clock)
# Create lines
printNicely(' '.join(ary))
+def format_quote(tweet):
+ """
+ Quoting format
+ """
+ # Retrieve info
+ screen_name = '@' + tweet['user']['screen_name']
+ text = tweet['text']
+ # Validate quote format
+ if '#owner' not in c['QUOTE_FORMAT']:
+ printNicely(light_magenta('Quote should contains #owner'))
+ return False
+ if '#comment' not in c['QUOTE_FORMAT']:
+ printNicely(light_magenta('Quote format should have #comment'))
+ return False
+ # Build formater
+ formater = ''
+ try:
+ formater = c['QUOTE_FORMAT']
+ formater = screen_name.join(formater.split('#owner'))
+ formater = text.join(formater.split('#tweet'))
+ formater = u2str(formater)
+ except:
+ pass
+ # Highlight like a tweet
+ notice = formater.split()
+ notice = lmap(
+ lambda x: light_green(x)
+ if x == '#comment'
+ else x,
+ notice)
+ notice = lmap(
+ lambda x: color_func(c['TWEET']['rt'])(x)
+ if x == 'RT'
+ else x,
+ notice)
+ notice = lmap(lambda x: cycle_color(x) if x[0] == '@' else x, notice)
+ notice = lmap(
+ lambda x: color_func(c['TWEET']['link'])(x)
+ if x[0:4] == 'http'
+ else x,
+ notice)
+ notice = lmap(
+ lambda x: color_func(c['TWEET']['hashtag'])(x)
+ if x.startswith('#')
+ else x,
+ notice)
+ notice = ' '.join(notice)
+ # Notice
+ notice = light_magenta('Quoting: "') + notice + light_magenta('"')
+ printNicely(notice)
+ return formater
+
+
# Start the color cycle
start_cycle()