Skip to content

Commit

Permalink
Merge pull request #31 from GoogleCloudPlatform/caching
Browse files Browse the repository at this point in the history
Update Discovery Doc Caching
  • Loading branch information
Jonathan Wayne Parrott committed May 22, 2015
2 parents c58e810 + 6dbfe79 commit 78079cd
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 13 deletions.
5 changes: 2 additions & 3 deletions bigquery/samples/async_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ def main():
query_string = raw_input("Enter the Bigquery SQL Query: ")
batch = raw_input("Run query as batch (y/n)?: ") in (
'True', 'true', 'y', 'Y', 'yes', 'Yes')

num_retries = raw_input(
"Enter number of times to retry in case of 500 error: ")
num_retries = int(raw_input(
"Enter number of times to retry in case of 500 error: "))
interval = raw_input(
"Enter how often to poll the query for completion (seconds): ")

Expand Down
8 changes: 6 additions & 2 deletions bigquery/samples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@

# [START get_service]
def get_service():
from discovery_doc import build_and_update
return build_and_update('bigquery', 'v2')
from googleapiclient.discovery import build
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
if credentials.create_scoped_required():
credentials = credentials.create_scoped('https://www.googleapis.com/auth/bigquery')
return build('bigquery','v2', credentials=GoogleCredentials.get_application_default())
# [END get_service]


Expand Down
59 changes: 56 additions & 3 deletions datastore/ndb/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,58 @@
appengine-ndb-snippets
======================
## NDB Overview Sample

Sample code snippets for NDB.
This is a sample app for Google App Engine that exercises the [NDB Python API](https://cloud.google.com/appengine/docs/python/ndb/).

See our other [Google Cloud Platform github
repos](https://github.com/GoogleCloudPlatform) for sample applications and
scaffolding for other python frameworks and use cases.

## Run Locally
1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/), including the [gcloud tool](https://cloud.google.com/sdk/gcloud/), and [gcloud app component](https://cloud.google.com/sdk/gcloud-app).
2. Setup the gcloud tool.

```
gcloud components update app
gcloud auth login
gcloud config set project <your-app-id>
```
You don't need a valid app-id to run locally, but will need a valid id to deploy below.

1. Clone this repo.

```
git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
cd python-docs-samples/datastore/ndb/<sub-directory>
```

1. Run this project locally from the command line.

```
gcloud preview app run ./
```

1. Visit the application at [http://localhost:8080](http://localhost:8080).

## Deploying

1. Use the [Cloud Developer Console](https://console.developer.google.com) to create a project/app id. (App id and project id are identical)
2. Configure gcloud with your app id.

```
gcloud config set project <your-app-id>
```
1. Use the [Admin Console](https://appengine.google.com) to view data, queues, and other App Engine specific administration tasks.
1. Use gcloud to deploy your app.

```
gcloud preview app deploy ./
```

1. Congratulations! Your application is now live at your-app-id.appspot.com

## Contributing changes

* See [CONTRIBUTING.md](../../CONTRIBUTING.md)

## Licensing

* See [LICENSE](../../LICENSE)
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@

RESOURCE_PATH = '..' # look for discovery docs in the parent folder
MAX_AGE = 86400 # update discovery docs older than a day
BIGQUERY_SCOPES = ['https://www.googleapis.com/auth/bigquery']


def build_and_update(api, version):
def build_and_update(api, version, scopes=None):
from oauth2client.client import GoogleCredentials
from googleapiclient.discovery import build_from_document

Expand All @@ -42,8 +40,8 @@ def build_and_update(api, version):
_update_discovery_doc(api, version, path)

credentials = GoogleCredentials.get_application_default()
if credentials.create_scoped_required():
credentials = credentials.create_scoped(BIGQUERY_SCOPES)
if scopes is not None and credentials.create_scoped_required():
credentials = credentials.create_scoped(scopes)
with open(path, 'r') as discovery_doc:
return build_from_document(discovery_doc.read(),
http=httplib2.Http(),
Expand Down

0 comments on commit 78079cd

Please sign in to comment.