open url and quote
authorOrakaro <nhatminh_179@hotmail.com>
Mon, 7 Jul 2014 14:07:48 +0000 (23:07 +0900)
committerOrakaro <nhatminh_179@hotmail.com>
Mon, 7 Jul 2014 14:07:48 +0000 (23:07 +0900)
rainbowstream/rainbow.py
setup.py

index 29fbc537e1c28f67cd78b3d67326f90e1c64beb9..f5daa81f9f833757ab2a7e43011f75d043f0c016 100644 (file)
@@ -10,6 +10,7 @@ import signal
 import argparse
 import time
 import requests
 import argparse
 import time
 import requests
+import webbrowser
 
 from twitter.stream import TwitterStream, Timeout, HeartbeatTimeout, Hangup
 from twitter.api import *
 
 from twitter.stream import TwitterStream, Timeout, HeartbeatTimeout, Hangup
 from twitter.api import *
@@ -36,6 +37,7 @@ cmdset = [
     'mentions',
     't',
     'rt',
     'mentions',
     't',
     'rt',
+    'quote',
     'allrt',
     'fav',
     'rep',
     'allrt',
     'fav',
     'rep',
@@ -44,6 +46,7 @@ cmdset = [
     's',
     'mes',
     'show',
     's',
     'mes',
     'show',
+    'open',
     'ls',
     'inbox',
     'sent',
     'ls',
     'inbox',
     'sent',
@@ -310,6 +313,30 @@ def retweet():
     t.statuses.retweet(id=tid, include_entities=False, trim_user=True)
 
 
     t.statuses.retweet(id=tid, include_entities=False, trim_user=True)
 
 
+def quote():
+    """
+    Quote a tweet
+    """
+    t = Twitter(auth=authen())
+    try:
+        id = int(g['stuff'].split()[0])
+    except:
+        printNicely(red('Sorry I can\'t understand.'))
+        return
+    tid = db.rainbow_to_tweet_query(id)[0].tweet_id
+    tweet = t.statuses.show(id=tid)
+    screen_name = tweet['user']['screen_name']
+    text = tweet['text']
+    quote = '\"@' + screen_name + ': ' + text + '\"'
+    quote = quote.encode('utf8')
+    printNicely(light_magenta('Compose mode:'))
+    extra = raw_input(quote)
+    if extra:
+        t.statuses.update(status=quote+extra)
+    else:
+        printNicely(light_magenta('No text added.'))
+
+
 def allretweet():
     """
     List all retweet
 def allretweet():
     """
     List all retweet
@@ -464,6 +491,26 @@ def show():
         printNicely(red('Sorry I can\'t show this image.'))
 
 
         printNicely(red('Sorry I can\'t show this image.'))
 
 
+def open():
+    """
+    Open url
+    """
+    t = Twitter(auth=authen())
+    try:
+        if not g['stuff'].isdigit():
+            return
+        tid = db.rainbow_to_tweet_query(g['stuff'])[0].tweet_id
+        tweet = t.statuses.show(id=tid)
+        link_ary = [u for u in tweet['text'].split() if u.startswith('http://')]
+        if not link_ary:
+            printNicely(light_magenta('No url here @.@!'))
+            return
+        for link in link_ary:
+            webbrowser.open(link)
+    except:
+        printNicely(red('Sorry I can\'t open url in this tweet.'))
+
+
 def list():
     """
     List friends for followers
 def list():
     """
     List friends for followers
@@ -859,6 +906,10 @@ def help():
     usage += s * 2 + \
         light_green('rt 12 ') + ' will retweet to tweet with ' + \
         light_yellow('[id=12]') + '.\n'
     usage += s * 2 + \
         light_green('rt 12 ') + ' will retweet to tweet with ' + \
         light_yellow('[id=12]') + '.\n'
+    usage += s * 2 + \
+        light_green('quote 12 ') + ' will quote the tweet with ' + \
+        light_yellow('[id=12]') + '. If no extra text is added, ' + \
+        'the quote will be canceled.\n'
     usage += s * 2 + \
         light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
         light_yellow('[id=12]') + '.\n'
     usage += s * 2 + \
         light_green('allrt 12 20 ') + ' will list 20 newest retweet of the tweet with ' + \
         light_yellow('[id=12]') + '.\n'
@@ -876,6 +927,8 @@ def help():
         light_yellow('[id=12]') + '.\n'
     usage += s * 2 + light_green('show image 12') + ' will show image in tweet with ' + \
         light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
         light_yellow('[id=12]') + '.\n'
     usage += s * 2 + light_green('show image 12') + ' will show image in tweet with ' + \
         light_yellow('[id=12]') + ' in your OS\'s image viewer.\n'
+    usage += s * 2 + light_green('open 12') + ' will open url in tweet with ' + \
+        light_yellow('[id=12]') + ' in your OS\'s default browser.\n'
 
     # Direct message
     usage += '\n'
 
     # Direct message
     usage += '\n'
@@ -1000,6 +1053,7 @@ def process(cmd):
             mentions,
             tweet,
             retweet,
             mentions,
             tweet,
             retweet,
+            quote,
             allretweet,
             favorite,
             reply,
             allretweet,
             favorite,
             reply,
@@ -1008,6 +1062,7 @@ def process(cmd):
             search,
             message,
             show,
             search,
             message,
             show,
+            open,
             list,
             inbox,
             sent,
             list,
             inbox,
             sent,
@@ -1044,6 +1099,7 @@ def listen():
             [],  # mentions
             [],  # tweet
             [],  # retweet
             [],  # mentions
             [],  # tweet
             [],  # retweet
+            [],  # quote
             [],  # allretweet
             [],  # favorite
             [],  # reply
             [],  # allretweet
             [],  # favorite
             [],  # reply
@@ -1052,6 +1108,7 @@ def listen():
             ['#'],  # search
             ['@'],  # message
             ['image'],  # show image
             ['#'],  # search
             ['@'],  # message
             ['image'],  # show image
+            [''],  # open url
             ['fl', 'fr'],  # list
             [],  # inbox
             [],  # sent
             ['fl', 'fr'],  # list
             [],  # inbox
             [],  # sent
index af1e35c2590f110364b135b88acdf5c965802b4e..fb6389ae85e0cff6080f9164c4fba8add08f3afa 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
 from setuptools import setup, find_packages
 
 from setuptools import setup, find_packages
 
-version = '0.2.1'
+version = '0.2.2'
 
 install_requires = [
     "SQLAlchemy",
 
 install_requires = [
     "SQLAlchemy",