'--proxy-type',
default='SOCKS5',
help='Proxy type (HTTP, SOCKS4, SOCKS5; Default: SOCKS5).')
+ parser.add_argument(
+ '-ta',
+ '--twitter-auth',
+ default=os.environ.get('HOME', os.environ.get('USERPROFILE', '')) + os.sep + '.rainbow_oauth',
+ help='Specify which OAuth profile to use for twitter. Default: ~/.rainbow_oauth.')
+ parser.add_argument(
+ '-pa',
+ '--pocket-auth',
+ default=os.environ.get('HOME', os.environ.get('USERPROFILE', '')) + os.sep + '.rainbow_pckt_oauth',
+ help='Specify which OAuth profile to use for pocket. Default: ~/.rainbow_pckt_oauth.')
return parser.parse_args()
Authenticate with Twitter OAuth
"""
# When using rainbow stream you must authorize.
- twitter_credential = os.environ.get(
- 'HOME',
- os.environ.get(
- 'USERPROFILE',
- '')) + os.sep + '.rainbow_oauth'
+ twitter_credential = g['twitter_oauth_path']
if not os.path.exists(twitter_credential):
oauth_dance('Rainbow Stream',
CONSUMER_KEY,
"""
Authenticate with Pocket OAuth
"""
- pocket_credential = os.environ.get(
- 'HOME',
- os.environ.get(
- 'USERPROFILE',
- '')) + os.sep + '.rainbow_pckt_oauth'
-
+ pocket_credential = g['pocket_oauth_path']
if not os.path.exists(pocket_credential):
request_token = Pocket.get_request_token(consumer_key=PCKT_CONSUMER_KEY)
auth_url = Pocket.get_auth_url(code=request_token, redirect_uri="/")
# Handle Ctrl C
ctrl_c_handler = lambda signum, frame: quit()
signal.signal(signal.SIGINT, ctrl_c_handler)
+ # Set OAuth file path (needs to happen before authen is called)
+ g['twitter_oauth_path'] = args.twitter_auth
+ g['pocket_oauth_path'] = args.pocket_auth
# Upgrade notify
upgrade_center()
# Get name
g['since_id'] = result[0]['id']
for tweet in reversed(result):
draw(t=tweet)
- printNicely('')
+ if result:
+ printNicely('')
def home():
"""
# Return results
if rel:
printNicely('Newest tweets:')
- for i in reversed(xrange(count)):
+ for i in reversed(xrange(min(len(rel), count))):
draw(t=rel[i], keyword=query)
printNicely('')
else:
"""
Tweet
"""
- t = Twitter(auth=authen())
- t.statuses.update(status=g['stuff'])
+ # Regex to check if tweet contains '--i' pattern
+ pattern = '(.*) --i (.+)'
+ m = re.match(pattern, g['stuff'])
+
+ if m is None:
+ # text only tweet
+ t = Twitter(auth=authen())
+ t.statuses.update(status=g['stuff'])
+ else:
+ # A tweet with media items
+ body = m.group(1)
+ imagePaths = m.group(2)
+ # Generating image ids
+ imageIds = []
+ for impath in imagePaths.split(','):
+ imagedata = open(impath, 'rb').read()
+
+ # upload media
+ t_up = Twitter(domain='upload.twitter.com',
+ auth=authen())
+ img_id = t_up.media.upload(media=imagedata)["media_id_string"]
+ imageIds.append(img_id)
+
+ # send your tweet with the list of media ids:
+ t = Twitter(auth=authen())
+ t.statuses.update(status=body, media_ids=",".join(imageIds))
def pocket():
"""
# Get inbox messages
messages = t.direct_messages.events.list()['events']
messages = list(map(map_message, messages))
- inbox = filter(inboxFilter, messages)
- sent = filter(inboxFilter, messages)
+ inbox = list(filter(inboxFilter, messages))
+ sent = list(filter(sentFilter, messages))
d = {}
uniq_inbox = list(set(
# Redefine decorated_name
g['decorated_name'] = lambda x: color_func(
c['DECORATED_NAME'])(
- '[' + x + ']: ')
+ '[' + x + ']: ', rl=True)
printNicely(green('Theme changed.'))
except:
printNicely(red('No such theme exists.'))
if key == 'THEME':
c['THEME'] = reload_theme(value, c['THEME'])
g['decorated_name'] = lambda x: color_func(
- c['DECORATED_NAME'])('[' + x + ']: ')
+ c['DECORATED_NAME'])('[' + x + ']: ', rl=True)
elif key == 'PREFIX':
g['PREFIX'] = u2str(emojize(format_prefix(
listname=g['listname'],
usage = '\n'
usage += s + grey(u'\u266A' + ' Tweets \n')
usage += s * 2 + light_green('t oops ') + \
- 'will tweet "' + light_yellow('oops') + '" immediately.\n'
+ 'will tweet "' + light_yellow('oops') + '" immediately.\n' + \
+ s * 3 + ' Optionally you can add --i <img1path>[,<img2path>,...] argument, e.g:\n' + \
+ s * 3 + light_yellow(' t This tweet has images --i /path/to/test1.png,relative_test.jpg') + '\n'
usage += s * 2 + \
light_green('rt 12 ') + ' will retweet to tweet with ' + \
light_yellow('[id=12]') + '.\n'
printNicely('')
except TwitterHTTPError as e:
detail_twitter_error(e)
- except Exception:
- debug_option()
- printNicely(red('OMG something is wrong with Twitter API right now.'))
finally:
# Release the semaphore lock
c['lock'] = False