Joe Gregorio | 34044bc | 2011-03-07 16:58:33 -0500 | [diff] [blame^] | 1 | #!/usr/bin/python2.4 |
| 2 | # -*- coding: utf-8 -*- |
| 3 | # |
| 4 | # Copyright 2010 Google Inc. All Rights Reserved. |
| 5 | |
| 6 | """Simple command-line example for Translate. |
| 7 | |
| 8 | Command-line application that translates |
| 9 | some text. |
| 10 | """ |
| 11 | |
| 12 | __author__ = 'jcgregorio@google.com (Joe Gregorio)' |
| 13 | |
| 14 | import gflags |
| 15 | import logging |
| 16 | import pprint |
| 17 | import sys |
| 18 | |
| 19 | from apiclient.discovery import build |
| 20 | from apiclient.model import LoggingJsonModel |
| 21 | |
| 22 | |
| 23 | FLAGS = gflags.FLAGS |
| 24 | # Uncomment the next line to get very detailed logging |
| 25 | # httplib2.debuglevel = 4 |
| 26 | |
| 27 | # create logger |
| 28 | logger = logging.getLogger() |
| 29 | logger.setLevel(logging.INFO) |
| 30 | |
| 31 | |
| 32 | def main(argv): |
| 33 | try: |
| 34 | argv = FLAGS(argv) # parse flags |
| 35 | except gflags.FlagsError, e: |
| 36 | print '%s\\nUsage: %s ARGS\\n%s' % (e, argv[0], FLAGS) |
| 37 | sys.exit(1) |
| 38 | |
| 39 | service = build('translate', 'v2', |
| 40 | developerKey='AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0', |
| 41 | model=LoggingJsonModel()) |
| 42 | print service.translations().list( |
| 43 | source='en', |
| 44 | target='fr', |
| 45 | q=['flower', 'car'] |
| 46 | ).execute() |
| 47 | |
| 48 | if __name__ == '__main__': |
| 49 | main(sys.argv) |