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 |
Matt McDonald | 2a5f413 | 2011-04-29 16:32:27 -0400 | [diff] [blame^] | 20 | from apiclient.model import JsonModel |
Joe Gregorio | 34044bc | 2011-03-07 16:58:33 -0500 | [diff] [blame] | 21 | |
| 22 | |
| 23 | FLAGS = gflags.FLAGS |
Joe Gregorio | 34044bc | 2011-03-07 16:58:33 -0500 | [diff] [blame] | 24 | logger = logging.getLogger() |
| 25 | logger.setLevel(logging.INFO) |
| 26 | |
| 27 | |
| 28 | def main(argv): |
Joe Gregorio | 3157a74 | 2011-03-08 10:54:07 -0500 | [diff] [blame] | 29 | try: |
| 30 | argv = FLAGS(argv) |
| 31 | except gflags.FlagsError, e: |
| 32 | print '%s\\nUsage: %s ARGS\\n%s' % (e, argv[0], FLAGS) |
| 33 | sys.exit(1) |
| 34 | |
Joe Gregorio | 34044bc | 2011-03-07 16:58:33 -0500 | [diff] [blame] | 35 | service = build('translate', 'v2', |
Joe Gregorio | afdf50b | 2011-03-08 09:41:52 -0500 | [diff] [blame] | 36 | developerKey='AIzaSyAQIKv_gwnob-YNrXV2stnY86GSGY81Zr0', |
Matt McDonald | 2a5f413 | 2011-04-29 16:32:27 -0400 | [diff] [blame^] | 37 | model=JsonModel()) |
Joe Gregorio | 34044bc | 2011-03-07 16:58:33 -0500 | [diff] [blame] | 38 | print service.translations().list( |
| 39 | source='en', |
| 40 | target='fr', |
| 41 | q=['flower', 'car'] |
| 42 | ).execute() |
| 43 | |
| 44 | if __name__ == '__main__': |
| 45 | main(sys.argv) |