Skip to content

Commit 78079cd

Browse files
author
Jonathan Wayne Parrott
committed
Merge pull request #31 from GoogleCloudPlatform/caching
Update Discovery Doc Caching
2 parents c58e810 + 6dbfe79 commit 78079cd

File tree

4 files changed

+67
-13
lines changed

4 files changed

+67
-13
lines changed

bigquery/samples/async_query.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ def main():
7474
query_string = raw_input("Enter the Bigquery SQL Query: ")
7575
batch = raw_input("Run query as batch (y/n)?: ") in (
7676
'True', 'true', 'y', 'Y', 'yes', 'Yes')
77-
78-
num_retries = raw_input(
79-
"Enter number of times to retry in case of 500 error: ")
77+
num_retries = int(raw_input(
78+
"Enter number of times to retry in case of 500 error: "))
8079
interval = raw_input(
8180
"Enter how often to poll the query for completion (seconds): ")
8281

bigquery/samples/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515

1616
# [START get_service]
1717
def get_service():
18-
from discovery_doc import build_and_update
19-
return build_and_update('bigquery', 'v2')
18+
from googleapiclient.discovery import build
19+
from oauth2client.client import GoogleCredentials
20+
credentials = GoogleCredentials.get_application_default()
21+
if credentials.create_scoped_required():
22+
credentials = credentials.create_scoped('https://www.googleapis.com/auth/bigquery')
23+
return build('bigquery','v2', credentials=GoogleCredentials.get_application_default())
2024
# [END get_service]
2125

2226

datastore/ndb/README.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,58 @@
1-
appengine-ndb-snippets
2-
======================
1+
## NDB Overview Sample
32

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

5+
See our other [Google Cloud Platform github
6+
repos](https://github.com/GoogleCloudPlatform) for sample applications and
7+
scaffolding for other python frameworks and use cases.
8+
9+
## Run Locally
10+
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).
11+
2. Setup the gcloud tool.
12+
13+
```
14+
gcloud components update app
15+
gcloud auth login
16+
gcloud config set project <your-app-id>
17+
```
18+
You don't need a valid app-id to run locally, but will need a valid id to deploy below.
19+
20+
1. Clone this repo.
21+
22+
```
23+
git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
24+
cd python-docs-samples/datastore/ndb/<sub-directory>
25+
```
26+
27+
1. Run this project locally from the command line.
28+
29+
```
30+
gcloud preview app run ./
31+
```
32+
33+
1. Visit the application at [http://localhost:8080](http://localhost:8080).
34+
35+
## Deploying
36+
37+
1. Use the [Cloud Developer Console](https://console.developer.google.com) to create a project/app id. (App id and project id are identical)
38+
2. Configure gcloud with your app id.
39+
40+
```
41+
gcloud config set project <your-app-id>
42+
```
43+
1. Use the [Admin Console](https://appengine.google.com) to view data, queues, and other App Engine specific administration tasks.
44+
1. Use gcloud to deploy your app.
45+
46+
```
47+
gcloud preview app deploy ./
48+
```
49+
50+
1. Congratulations! Your application is now live at your-app-id.appspot.com
51+
52+
## Contributing changes
53+
54+
* See [CONTRIBUTING.md](../../CONTRIBUTING.md)
55+
56+
## Licensing
57+
58+
* See [LICENSE](../../LICENSE)

bigquery/samples/discovery_doc.py renamed to discoverydoccaching/discovery_doc.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626

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

31-
32-
def build_and_update(api, version):
30+
def build_and_update(api, version, scopes=None):
3331
from oauth2client.client import GoogleCredentials
3432
from googleapiclient.discovery import build_from_document
3533

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

4442
credentials = GoogleCredentials.get_application_default()
45-
if credentials.create_scoped_required():
46-
credentials = credentials.create_scoped(BIGQUERY_SCOPES)
43+
if scopes is not None and credentials.create_scoped_required():
44+
credentials = credentials.create_scoped(scopes)
4745
with open(path, 'r') as discovery_doc:
4846
return build_from_document(discovery_doc.read(),
4947
http=httplib2.Http(),

0 commit comments

Comments
 (0)