Skip to content

Instantly share code, notes, and snippets.

@rafaelmartins
Created April 19, 2011 19:41
Show Gist options
  • Save rafaelmartins/929417 to your computer and use it in GitHub Desktop.
Save rafaelmartins/929417 to your computer and use it in GitHub Desktop.
wtf-server.co.cc client
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
wtf
---
This is the wtf-server.co.cc client. It is based on the old `wtf` game, from
NetBSD, but with a remote backend.
Usage example::
$ wtf is wtf
:License: Public domain.
"""
import os, socket, sys
from xmlrpclib import ServerProxy
SERVER_URL = 'http://wtf-server.co.cc'
def main(argv):
if len(argv) == 3 and argv[1] == 'is':
argv.pop(1)
if len(argv) != 2:
print >> sys.stderr, 'Invalid number of arguments.'
return os.EX_USAGE
try:
rpc = ServerProxy(SERVER_URL)
except Exception, e:
print >> sys.stderr, 'Invalid XML-RPC server: %s' % e
return os.EX_IOERR
try:
translations = rpc.wtf_is(argv[1])
except socket.error, e:
print >> sys.stderr, 'Failed to request data from the server: %s' % e
return os.EX_PROTOCOL
if len(translations) == 0:
print '%s: nothing appropriate' % argv[1].upper()
return os.EX_UNAVAILABLE
for translation in translations:
print '%s: %s' % (argv[1].upper(), translation)
return os.EX_OK
if __name__ == '__main__':
sys.exit(main(sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment