Skip to content

Instantly share code, notes, and snippets.

@TylerLubeck
Last active December 26, 2015 09:39
Show Gist options
  • Save TylerLubeck/7131188 to your computer and use it in GitHub Desktop.
Save TylerLubeck/7131188 to your computer and use it in GitHub Desktop.
A much simpler way to tweet
#!/usr/bin/python
# To Install:
# This script will go in your git directory, in the folder .git/hooks
# It has to be called "post-commit", so the final path will be
# MYGITPROJECT/.git/hooks/post-commit
# Then give this script execute permissions:
# chmod +x MYGITPROJECT/.git/hooks/post-commit
# Then change the GROUP_NAME to your group name. This allows for some fun analytics later
import sys
import urllib, urllib2
from subprocess import check_output
GROUP_NAME = 'TooLazyToChangeGroupName' #Insert a group name here
URL = 'http://thcl.herokuapp.com/tweet'
if __name__ == "__main__":
#Get commit message
msg = check_output(["git", "log", "-1", "HEAD", "--pretty=format:%s"])
data = {'status': msg, 'project': GROUP_NAME}
req = urllib2.Request(URL)
req.add_data(urllib.urlencode(data))
try:
urllib2.urlopen(req)
print "Thank you for pushing to the Tufts Hack Commit Logger!"
except Exception as e:
print "Something went wrong pushing your tweet, sorry!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment