Last active
August 29, 2015 14:21
-
-
Save wcaleb/60d52759f6d0c5bc270d to your computer and use it in GitHub Desktop.
Revisions
-
wcaleb revised this gist
May 13, 2015 . 1 changed file with 15 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -19,31 +19,39 @@ api_secret = wcaleb['api_secret'] access_token = wcaleb['access_token'] access_token_secret = wcaleb['access_token_secret'] base_url = 'http://wiki.wcaleb.rice.edu/' repo = git.Repo('/home/wcm1/wiki/wikidata') most_recent_diff = repo.head.commit.diff('HEAD~1') changed_files = [] for x in most_recent_diff: if x.a_blob.path not in changed_files: changed_files.append(x.a_blob.path) if x.b_blob is not None and x.b_blob.path not in changed_files: changed_files.append(x.b_blob.path) # Filter out changed discussion pages def isNotDiscuss(file): return file[0] != '@' filter_files = [os.path.splitext(n)[0] for n in filter(isNotDiscuss, changed_files)] if len(filter_files) == 1: pageUrl = urllib.pathname2url(filter_files[0]) url = base_url + '_diff/' + pageUrl + '?to=' + repo.head.commit.hexsha else: url = base_url + '_activity' file_names = ', '.join(filter_files) if len(file_names) < 80: tweet = 'Updated notes on ' + file_names + ' in my research wiki. ' + url else: tweet = 'Updated notes in my research wiki. ' + url try: api = twitter.Api(consumer_key = api_key, consumer_secret = api_secret, access_token_key = access_token, access_token_secret = access_token_secret) status = api.PostUpdate(tweet) except twitter.TwitterError, error: print(error.message) exit() -
wcaleb revised this gist
May 13, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -24,6 +24,8 @@ most_recent_diff = repo.head.commit.diff('HEAD~1') changed_files = [] # This bit of black magic comes from http://www.masnun.com/2012/01/28/fetching-changed-files-diff-between-two-git-commits-in-python.html for x in most_recent_diff: if x.a_blob.path not in changed_files: changed_files.append(x.a_blob.path) -
wcaleb created this gist
May 13, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ #!/usr/bin/python # I run a wiki on Gitit at http://wiki.wcaleb.rice.edu. It's usually # updated by pushing to the wiki's remote git repo from my local machine. # I have a `post-receive` hook in that repo that runs this script, like so: # # unset GIT_DIR # python /path/to/wikitweet.py # # Now, whenever I push to the repo, the script looks to see which files have # been changed and tweets about the update to https://twitter.com/wcaleb import os import twitter # https://github.com/bear/python-twitter import git # http://gitpython.readthedocs.org/en/stable/index.html from OAuthSettings import wcaleb api_key = wcaleb['api_key'] api_secret = wcaleb['api_secret'] access_token = wcaleb['access_token'] access_token_secret = wcaleb['access_token_secret'] repo = git.Repo('/home/wcm1/wiki/wikidata') most_recent_diff = repo.head.commit.diff('HEAD~1') changed_files = [] for x in most_recent_diff: if x.a_blob.path not in changed_files: changed_files.append(x.a_blob.path) if x.b_blob is not None and x.b_blob.path not in changed_files: changed_files.append(x.b_blob.path) def isNotDiscuss(file): return file[0] != '@' file_names = ', '.join([os.path.splitext(n)[0] for n in filter(isNotDiscuss, changed_files)]) if len(file_names) < 80: tweet = 'Updated notes on ' + file_names + ' in my research wiki. http://wiki.wcaleb.rice.edu/_activity' else: tweet = 'Updated notes in my research wiki. http://wiki.wcaleb.rice.edu/_activity' try: api = twitter.Api(consumer_key = api_key, consumer_secret = api_secret, access_token_key = access_token, access_token_secret = access_token_secret) status = api.PostUpdate(tweet) except twitter.TwitterError: exit()