Skip to content

Instantly share code, notes, and snippets.

@timbennett
Last active August 25, 2016 04:55
Show Gist options
  • Save timbennett/09a52b185f0bcd7c596031abad7714c9 to your computer and use it in GitHub Desktop.
Save timbennett/09a52b185f0bcd7c596031abad7714c9 to your computer and use it in GitHub Desktop.
IFTTT alert if Twitter username is available
## Check whether a specified Twitter username is available.
## Usage: 'check.py username'
## IFTTT.com instructions:
## You will need an ifttt.com account. Activate the maker channel (https://ifttt.com/maker) and copy your key to this script.
## Create a new recipe with trigger "Receive a web request" from the Maker channel.
## The script will send the username as Value1 and status as Value2. You can use these in your recipe.
## e.g. "Twitter username {{Value1}} {{Value2}}" will come across as "Twitter username jack available"
import requests
import sys
## Copy your maker channel key here:
maker_key = '###'
## Copy the recipe event name field here (e.g. "on_username_available"):
event_name = '###'
## Get the username provided in the command line argument (else use @jack)
try:
username = sys.argv[1]
except:
username = 'jack'
## Check the username and store the response
url = 'https://twitter.com/users/username_available?username={0}&value={1}'.format(username,username)
r = requests.get(url)
status = r.json()
## If the username is available, send the trigger to ifttt
if status['reason'] == 'available':
payload = {'value1': username, 'value2' : status['reason']}
requests.post('https://maker.ifttt.com/trigger/{0}/with/key/{1}'.format(event_name,maker_key), data=payload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment