Skip to content

Instantly share code, notes, and snippets.

@dentearl
Created December 22, 2012 02:16
Show Gist options
  • Save dentearl/4357071 to your computer and use it in GitHub Desktop.
Save dentearl/4357071 to your computer and use it in GitHub Desktop.
script to programmatically change your gchat status. Can take input via positional arguments and standard in.
#!/usr/bin/env python
"""
gstatus.py,
21 December 2012
dent earl, dent.earl (a) gmail com
a script to programmatically change your gchat status.
based in large part on a script from CyberShadow:
http://blog.thecybershadow.net/2010/05/08/setting-shared-google-talk-gmail-status-programmatically/
"""
from argparse import ArgumentParser
import libAuth
import sys
import warnings
warnings.filterwarnings("ignore") # silence DeprecationWarning messages
from xmpp import *
def initArgs(parser):
parser.add_argument('status', help=('the status message you wish to set. specify - to use '
'the last line of stdin'))
parser.add_argument('--show', dest='show', default='default', type=str,
help='must be either default or dnd. default=%(default)s')
def checkArgs(args, parser):
if args.show not in ['default', 'dnd']:
parser.error('Unrecognized selection for --show. Must be either default or dnd.')
def setStatus(args):
status = args.status
if status == '-':
for line in sys.stdin:
line = line.strip()
status = line # we just take the last line of stdin
cl=Client(server='gmail.com', debug=[])
if not cl.connect(server=('talk.google.com', 5222)):
raise IOError('Can not connect to server.')
if not cl.auth(libAuth.USERNAME, libAuth.PASSWORD, 'gmail.com'):
raise IOError('Can not auth with server.')
cl.send(Iq('set', 'google:shared-status', payload=[
Node('show', payload=[args.show]),
Node('status', payload=[status])
]))
cl.disconnect()
def main():
parser = ArgumentParser()
initArgs(parser)
args = parser.parse_args()
checkArgs(args, parser)
setStatus(args)
if __name__ == '__main__':
main()
# this file should be in the same directory as gstatus.py
# it should also be made to be read only for the owner, i.e. on linux
# run `chmod go-rwx libAuth.py'
USERNAME = 'user' # don't include @gmail.com
PASSWORD = 'a password' # you should think about using google's application specific passwords for this!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment