import threading
import requests
import webbrowser
+import traceback
+import pkg_resources
from twitter.stream import TwitterStream, Timeout, HeartbeatTimeout, Hangup
from twitter.api import *
from .interactive import *
from .c_image import *
from .py3patch import *
+from .emoji import *
# Global values
g = {}
return screen_name_list
+def debug_option():
+ """
+ Save traceback when run in debug mode
+ """
+ if g['debug']:
+ g['traceback'].append(traceback.format_exc())
+
+
+def upgrade_center():
+ """
+ Check latest and notify to upgrade
+ """
+ try:
+ current = pkg_resources.get_distribution("rainbowstream").version
+ url = 'https://raw.githubusercontent.com/DTVD/rainbowstream/master/setup.py'
+ readme = requests.get(url).content
+ latest = readme.split("version = \'")[1].split("\'")[0]
+ if current != latest:
+ notice = light_magenta('RainbowStream latest version is ')
+ notice += light_green(latest)
+ notice += light_magenta(' while your current version is ')
+ notice += light_yellow(current) + '\n'
+ notice += light_magenta('You should upgrade with "pip install -U rainbowstream".')
+ printNicely(notice)
+ except:
+ pass
+
+
def init(args):
"""
Init function
# Handle Ctrl C
ctrl_c_handler = lambda signum, frame: quit()
signal.signal(signal.SIGINT, ctrl_c_handler)
+ # Upgrade notify
+ upgrade_center()
# Get name
t = Twitter(auth=authen())
credential = t.account.verify_credentials()
name = credential['name']
if not get_config('PREFIX'):
set_config('PREFIX', screen_name)
+ c['PREFIX'] = emojize(c['PREFIX'])
g['PREFIX'] = u2str(c['PREFIX'])
c['original_name'] = g['original_name'] = screen_name[1:]
g['full_name'] = name
g['events'] = []
# Startup cmd
g['cmd'] = ''
+ # Debug option default = True
+ g['debug'] = True
+ g['traceback'] = []
+ # Retweet of mine events
+ c['events'] = []
# Semaphore init
c['lock'] = False
# Init tweet dict and message dict
"""
Show notifications
"""
+ g['events'] = g['events'] + c['events']
if g['events']:
for e in g['events']:
print_event(e)
include_entities=False)
show_profile(user)
except:
- printNicely(red('Omg no user.'))
+ debug_option()
+ printNicely(red('No user.'))
else:
printNicely(red('A name should begin with a \'@\''))
img = Image.open(BytesIO(res.content))
img.show()
except:
+ debug_option()
printNicely(red('Sorry I can\'t show this image.'))
for link in link_ary:
webbrowser.open(link)
except:
+ debug_option()
printNicely(red('Sorry I can\'t open url in this tweet.'))
g['original_name'],
g['full_name'])
except Exception:
+ debug_option()
printNicely(red('No such thread.'))
else:
printNicely(red('A name should begin with a \'@\''))
except:
+ debug_option()
printNicely(red('Sorry I can\'t understand.'))
else:
printNicely(red(rel))
except:
+ debug_option()
printNicely(red('Something is wrong, can not mute now :('))
else:
printNicely(red('A name should begin with a \'@\''))
screen_name=user_name)
printNicely(green('Added.'))
except:
+ debug_option()
printNicely(light_magenta('I\'m sorry we can not add him/her.'))
screen_name=user_name)
printNicely(green('Gone.'))
except:
+ debug_option()
printNicely(light_magenta('I\'m sorry we can not remove him/her.'))
owner_screen_name=owner)
printNicely(green('Done.'))
except:
+ debug_option()
printNicely(
light_magenta('I\'m sorry you can not subscribe to this list.'))
owner_screen_name=owner)
printNicely(green('Done.'))
except:
+ debug_option()
printNicely(
light_magenta('I\'m sorry you can not unsubscribe to this list.'))
description=description)
printNicely(green(name + ' list is created.'))
except:
+ debug_option()
printNicely(red('Oops something is wrong with Twitter :('))
description=description)
printNicely(green(slug + ' list is updated.'))
except:
+ debug_option()
printNicely(red('Oops something is wrong with Twitter :('))
owner_screen_name=g['original_name'])
printNicely(green(slug + ' list is deleted.'))
except:
+ debug_option()
printNicely(red('Oops something is wrong with Twitter :('))
try:
# raw_input
if g['prefix']:
+ # Only use PREFIX as a string with raw_input
line = raw_input(g['decorated_name'](g['PREFIX']))
else:
line = raw_input()
except EOFError:
printNicely('')
except Exception:
+ debug_option()
printNicely(red('OMG something is wrong with Twitter right now.'))
light_green("h stream") + \
light_magenta(" for more details.")
printNicely(guide)
- sys.stdout.write(g['decorated_name'](g['PREFIX']))
+ sys.stdout.write(g['decorated_name'](c['PREFIX']))
sys.stdout.flush()
StreamLock.release()
break
# the 1st character of that word
if current_buffer and g['cmd'] != current_buffer:
sys.stdout.write(
- g['decorated_name'](g['PREFIX']) + str2u(current_buffer))
+ g['decorated_name'](c['PREFIX']) + str2u(current_buffer))
sys.stdout.flush()
elif not c['HIDE_PROMPT']:
- sys.stdout.write(g['decorated_name'](g['PREFIX']))
+ sys.stdout.write(g['decorated_name'](c['PREFIX']))
sys.stdout.flush()
elif tweet.get('direct_message'):
# Check the semaphore pause and lock (stream process only)