Skip to content

Instantly share code, notes, and snippets.

@crock
Last active March 13, 2016 22:06
Show Gist options
  • Save crock/37167e5eb02867eee868 to your computer and use it in GitHub Desktop.
Save crock/37167e5eb02867eee868 to your computer and use it in GitHub Desktop.
Pythonista (iOS) script to fetch a Twitter status link from your clipboard and then like/favorite it
# coding: utf-8
import twitter
import json
import re
import clipboard
account = twitter.get_account('acrockr')
# Do not touch the code below
api = 'https://api.twitter.com/1.1/favorites/create.json'
regex = '^(http?s://?w?w?w?.twitter\.com/)([a-zA-Z0-9_]{1,15})(/status/)([0-9]{1,20})$'
def like_tweet(x):
pattern_match = re.findall(regex, x)
tup = pattern_match[0]
user = tup[1]
id = tup[3]
params = {'id':id}
status = twitter.request(account, api, 'POST', params)
def fetch_link_from_clipboard():
text = clipboard.get()
if re.match(regex, text):
print('Tweet link found in clipboard...')
like_tweet(text)
else:
print('Clipboard does not contain a link to a tweet.')
fetch_link_from_clipboard()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment