Last active
December 26, 2015 09:39
-
-
Save TylerLubeck/7131291 to your computer and use it in GitHub Desktop.
Submit your tweet both to the logger and to your personal twitter account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
# You will need to get the twitter python library, as such: | |
# pip install twitter | |
# You will also need Twitter OAuth Keys, which you can get at: | |
# https://dev.twitter.com/apps/new | |
# You'll need to create a new application. After it's created, you can get | |
# your consumer key and secret underneath "OAuth settings" and your | |
# access token and secret under "Your access token" | |
# (These are the OAuth_Token and Oauth_Secret). | |
# Finally, you'll need to give this application write permissions underneath | |
# the settings tab - Application Type. | |
# | |
# Also change GROUP_NAME to your group name, this allows for some fun analytics | |
use_twitter = True | |
import sys | |
import urllib, urllib2 | |
from subprocess import check_output | |
try: | |
from twitter import * | |
except ImportError: | |
print "Can't import twitter, have you installed it?" | |
use_twitter = False | |
##CHANGE THIS VALUE | |
GROUP_NAME = 'TooLazyToChangeGroupName' #Insert a group name here | |
URL = 'http://thcl.herokuapp.com/tweet' | |
TCK = TWITTER_CONSUMER_KEY = None #Should be a string, see instructions | |
TCS = TWITTER_CONSUMER_SECRET = None #Should be a string, see instructions | |
TOT = TWITTER_OAUTH_TOKEN = None #Should be a string, see instructions | |
TOS = TWITTER_OAUTH_SECRET = None #Should be a string, see instructions | |
if __name__ == "__main__": | |
#Check for keys | |
if not TCK or not TCS or not TOT or not TOS: | |
print "Seems like you haven't set your twitter keys yet..." | |
use_twitter = False | |
#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 to the Tufts Hack Commit Logger, sorry!" | |
if use_twitter: | |
if(len(msg) > 96): | |
msg = msg[0:93] + '...' | |
else: | |
msg = msg[0:96] | |
tweet = 'git commit -m "' + msg + '" #TuftsHack' | |
t = Twitter(auth=OAuth(TOT, TOS, TCK, TCS)) | |
t.statuses.update(status=tweet) | |
print 'Tweet: ' + tweet + 'sent!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment