Skip to content

Commit

Permalink
history.py will tweet result when --tweet option
Browse files Browse the repository at this point in the history
  • Loading branch information
hyaguchijsk committed Feb 1, 2011
1 parent d422fe1 commit be42c1b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
11 changes: 8 additions & 3 deletions python/history.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

import sys,os,getopt,re,time,datetime,locale
import tweet

def read_history(user,shell,histfile,year=None,month=None,day=None):
if os.path.exists(histfile):
Expand Down Expand Up @@ -69,18 +70,22 @@ def read_history(user,shell,histfile,year=None,month=None,day=None):
if __name__=="__main__":
args=sys.argv

opts,args = getopt.getopt(args[1:],"",["shell","histfile"])
opts,args = getopt.getopt(args[1:],"",["shell","histfile","tweet"])

shell_full=os.environ.get("SHELL").split("/")
shell=shell_full[len(shell_full)-1]
histfile=os.environ.get("HOME") + "/." + shell + "_history"
istweet=False
for opt,val in opts:
if opt == "--shell":
shell=val
if opt == "--histfile":
elif opt == "--histfile":
histfile=val
elif opt == "--tweet":
istweet=True

retstr = read_history(os.environ.get("USER"),shell,histfile)
if retstr != "":
print retstr

if istweet:
tweet.tweetstring(retstr)
22 changes: 22 additions & 0 deletions python/tweet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python

import os,tweepy

def read_auth_file(fname):
f=open(fname)
ret=f.readline().strip()
f.close()
return ret

def tweetstring(twstr):
homedir=os.environ.get("HOME")
consumer_key=read_auth_file(homedir + "/.twitter_consumer_key")
consumer_secret=read_auth_file(homedir + "/.twitter_consumer_secret")
access_key=read_auth_file(homedir + "/.twitter_access_key")
access_secret=read_auth_file(homedir + "/.twitter_access_secret")

auth=tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_key,access_secret)
twapi=tweepy.API(auth)
twapi.update_status(twstr)

0 comments on commit be42c1b

Please sign in to comment.