Joe Gregorio | 292b9b8 | 2011-01-12 11:36:11 -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 Buzz. |
| 7 | |
| 8 | Command-line application that retrieves the users |
| 9 | latest content and then adds a new entry. |
| 10 | """ |
| 11 | |
| 12 | __author__ = 'jcgregorio@google.com (Joe Gregorio)' |
| 13 | |
| 14 | from apiclient.discovery import build_from_document |
| 15 | |
| 16 | import httplib2 |
Joe Gregorio | f415342 | 2011-03-18 22:45:18 -0400 | [diff] [blame] | 17 | import os |
Joe Gregorio | 292b9b8 | 2011-01-12 11:36:11 -0500 | [diff] [blame] | 18 | import pprint |
| 19 | |
Joe Gregorio | 821e164 | 2011-05-04 10:19:17 -0400 | [diff] [blame^] | 20 | def main(): |
Joe Gregorio | 292b9b8 | 2011-01-12 11:36:11 -0500 | [diff] [blame] | 21 | http = httplib2.Http() |
Joe Gregorio | 292b9b8 | 2011-01-12 11:36:11 -0500 | [diff] [blame] | 22 | |
| 23 | # Load the local copy of the discovery document |
Joe Gregorio | f415342 | 2011-03-18 22:45:18 -0400 | [diff] [blame] | 24 | f = file(os.path.join(os.path.dirname(__file__), "buzz.json"), "r") |
Joe Gregorio | 292b9b8 | 2011-01-12 11:36:11 -0500 | [diff] [blame] | 25 | discovery = f.read() |
| 26 | f.close() |
| 27 | |
| 28 | # Optionally load a futures discovery document |
Joe Gregorio | f415342 | 2011-03-18 22:45:18 -0400 | [diff] [blame] | 29 | f = file(os.path.join(os.path.dirname(__file__), "../../apiclient/contrib/buzz/future.json"), "r") |
Joe Gregorio | 292b9b8 | 2011-01-12 11:36:11 -0500 | [diff] [blame] | 30 | future = f.read() |
| 31 | f.close() |
| 32 | |
| 33 | # Construct a service from the local documents |
Joe Gregorio | 1ae3e74 | 2011-02-25 15:17:14 -0500 | [diff] [blame] | 34 | service = build_from_document(discovery, |
Joe Gregorio | 292b9b8 | 2011-01-12 11:36:11 -0500 | [diff] [blame] | 35 | base="https://www.googleapis.com/", |
Joe Gregorio | 292b9b8 | 2011-01-12 11:36:11 -0500 | [diff] [blame] | 36 | http=http, |
Joe Gregorio | 821e164 | 2011-05-04 10:19:17 -0400 | [diff] [blame^] | 37 | future=future) |
Joe Gregorio | 292b9b8 | 2011-01-12 11:36:11 -0500 | [diff] [blame] | 38 | |
Joe Gregorio | 821e164 | 2011-05-04 10:19:17 -0400 | [diff] [blame^] | 39 | pprint.pprint(service.activities().search(q='lady gaga').execute()) |
Joe Gregorio | 292b9b8 | 2011-01-12 11:36:11 -0500 | [diff] [blame] | 40 | |
Joe Gregorio | 292b9b8 | 2011-01-12 11:36:11 -0500 | [diff] [blame] | 41 | |
| 42 | if __name__ == '__main__': |
Joe Gregorio | 821e164 | 2011-05-04 10:19:17 -0400 | [diff] [blame^] | 43 | main() |