Skip to content

Commit e3265d7

Browse files
committed
Update commits with incorrect email
1 parent 2494b59 commit e3265d7

File tree

18 files changed

+158
-68
lines changed

18 files changed

+158
-68
lines changed

appengine/standard/firebase/firenotes/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ Authentication, Google App Engine, and Google Cloud Datastore.
66

77
This sample is used on the following documentation page:
88

9-
<https://cloud.google.com/appengine/docs/python/authenticating-users-firebase-app-engine/>
9+
[https://cloud.google.com/appengine/docs/python/authenticating-users-firebase-appengine/](https://cloud.google.com/appengine/docs/python/authenticating-users-firebase-appengine/)
1010

11-
You'll need to have [Python 2.7](https://www.python.org/), the
12-
[App Engine SDK](https://cloud.google.com/appengine/downloads#Google_App_Engine_SDK_for_Python),
13-
and the [Google Cloud SDK](https://cloud.google.com/sdk/?hl=en)
11+
You'll need to have [Python 2.7](https://www.python.org/) and the [Google Cloud SDK](https://cloud.google.com/sdk/?hl=en)
1412
installed and initialized to an App Engine project before running the code in
1513
this sample.
1614

1715
## Setup
1816

1917
1. Clone this repo:
2018

21-
git clone https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard/firebase/firenotes
19+
git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
20+
21+
1. Navigate to the directory that contains the sample code:
22+
23+
cd python-docs-samples/appengine/standard/firebase/firenotes
2224

2325
1. Within a virtualenv, install the dependencies to the backend service:
2426

@@ -32,7 +34,7 @@ this sample.
3234
application on the App Engine local development server.
3335

3436
1. [Add Firebase to your app.](https://firebase.google.com/docs/web/setup#add_firebase_to_your_app)
35-
1. Add your Firebase Project ID to the backend’s `app.yaml` file as an
37+
1. Add your Firebase project ID to the backend’s `app.yaml` file as an
3638
environment variable.
3739
1. Select which providers you want to enable. Delete the providers from
3840
`main.js` that you do no want to offer. Enable the providers you chose to keep
@@ -49,7 +51,7 @@ server with the following command:
4951

5052
dev_appserver.py frontend/app.yaml backend/app.yaml
5153

52-
1. Visit <http://locahost:8080/> in a web browser.
54+
1. Visit [http://locahost:8080/](http://locahost:8080/) in a web browser.
5355

5456
## Deploy
5557
1. Change the backend host URL in `main.js` to

appengine/standard/firebase/firenotes/frontend/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
<script src="https://www.gstatic.com/firebasejs/3.2.1/firebase.js"></script>
1111
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-app.js"></script>
1212
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-auth.js"></script>
13-
<script src="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.js"></script>
14-
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/live/0.4/firebase-ui-auth.css">
13+
<script src="https://www.gstatic.com/firebasejs/ui/live/0.5/firebase-ui-auth.js"></script>
14+
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/live/0.5/firebase-ui-auth.css">
1515
<link rel="stylesheet" type="text/css" href="style.css">
1616
<script src="/main.js"></script>
1717
<title>Firenotes</title>

bigquery/cloud-client/export_data_to_gcs_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
DATASET_ID = 'test_dataset'
18-
TABLE_ID = 'test_import_table'
18+
TABLE_ID = 'test_table'
1919

2020

2121
def test_export_data_to_gcs(cloud_config, capsys):

bigquery/cloud-client/snippets.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
"""
2626

2727
import argparse
28+
import time
29+
import uuid
2830

2931
from gcloud import bigquery
32+
import gcloud.bigquery.job
3033

3134

3235
def list_projects():
@@ -82,6 +85,32 @@ def list_tables(dataset_name, project=None):
8285
print(table.name)
8386

8487

88+
def create_table(dataset_name, table_name, project=None):
89+
"""Creates a simple table in the given dataset.
90+
91+
If no project is specified, then the currently active project is used.
92+
"""
93+
bigquery_client = bigquery.Client(project=project)
94+
dataset = bigquery_client.dataset(dataset_name)
95+
96+
if not dataset.exists():
97+
print('Dataset {} does not exist.'.format(dataset_name))
98+
return
99+
100+
table = dataset.table(table_name)
101+
102+
# Set the table schema
103+
table.schema = (
104+
bigquery.SchemaField('Name', 'STRING'),
105+
bigquery.SchemaField('Age', 'INTEGER'),
106+
bigquery.SchemaField('Weight', 'FLOAT'),
107+
)
108+
109+
table.create()
110+
111+
print('Created table {} in dataset {}.'.format(table_name, dataset_name))
112+
113+
85114
def list_rows(dataset_name, table_name, project=None):
86115
"""Prints rows in the given table.
87116
@@ -126,6 +155,50 @@ def list_rows(dataset_name, table_name, project=None):
126155
print(format_string.format(*row))
127156

128157

158+
def copy_table(dataset_name, table_name, new_table_name, project=None):
159+
"""Copies a table.
160+
161+
If no project is specified, then the currently active project is used.
162+
"""
163+
bigquery_client = bigquery.Client(project=project)
164+
dataset = bigquery_client.dataset(dataset_name)
165+
table = dataset.table(table_name)
166+
167+
# This sample shows the destination table in the same dataset and project,
168+
# however, it's possible to copy across datasets and projects. You can
169+
# also copy muliple source tables into a single destination table by
170+
# providing addtional arguments to `copy_table`.
171+
destination_table = dataset.table(new_table_name)
172+
173+
# Create a job to copy the table to the destination table.
174+
job_id = str(uuid.uuid4())
175+
job = bigquery_client.copy_table(
176+
job_id, destination_table, table)
177+
178+
# Create the table if it doesn't exist.
179+
job.create_disposition = (
180+
gcloud.bigquery.job.CreateDisposition.CREATE_IF_NEEDED)
181+
182+
# Start the job.
183+
job.begin()
184+
185+
# Wait for the the job to finish.
186+
print('Waiting for job to finish...')
187+
wait_for_job(job)
188+
189+
print('Table {} copied to {}.'.format(table_name, new_table_name))
190+
191+
192+
def wait_for_job(job):
193+
while True:
194+
job.reload() # Refreshes the state via a GET request.
195+
if job.state == 'DONE':
196+
if job.error_result:
197+
raise RuntimeError(job.error_result)
198+
return
199+
time.sleep(1)
200+
201+
129202
def delete_table(dataset_name, table_name, project=None):
130203
"""Deletes a table in a given dataset.
131204
@@ -155,11 +228,22 @@ def delete_table(dataset_name, table_name, project=None):
155228
'list-tables', help=list_tables.__doc__)
156229
list_tables_parser.add_argument('dataset_name')
157230

231+
create_table_parser = subparsers.add_parser(
232+
'create-table', help=create_table.__doc__)
233+
create_table_parser.add_argument('dataset_name')
234+
create_table_parser.add_argument('table_name')
235+
158236
list_rows_parser = subparsers.add_parser(
159237
'list-rows', help=list_rows.__doc__)
160238
list_rows_parser.add_argument('dataset_name')
161239
list_rows_parser.add_argument('table_name')
162240

241+
copy_table_parser = subparsers.add_parser(
242+
'copy-table', help=copy_table.__doc__)
243+
copy_table_parser.add_argument('dataset_name')
244+
copy_table_parser.add_argument('table_name')
245+
copy_table_parser.add_argument('new_table_name')
246+
163247
delete_table_parser = subparsers.add_parser(
164248
'delete-table', help=delete_table.__doc__)
165249
delete_table_parser.add_argument('dataset_name')
@@ -171,7 +255,11 @@ def delete_table(dataset_name, table_name, project=None):
171255
list_datasets(args.project)
172256
elif args.command == 'list-tables':
173257
list_tables(args.dataset_name, args.project)
258+
elif args.command == 'create-table':
259+
create_table(args.dataset_name, args.table_name, args.project)
174260
elif args.command == 'list-rows':
175261
list_rows(args.dataset_name, args.table_name, args.project)
262+
elif args.command == 'copy-table':
263+
copy_table(args.dataset_name, args.table_name, args.new_table_name)
176264
elif args.command == 'delete-table':
177265
delete_table(args.dataset_name, args.table_name, args.project)

bigquery/cloud-client/snippets_test.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
DATASET_ID = 'test_dataset'
22-
TABLE_ID = 'test_import_table'
22+
TABLE_ID = 'test_table'
2323

2424

2525
@pytest.mark.xfail(
@@ -62,7 +62,42 @@ def test_list_rows(capsys):
6262
assert 'Age' in out
6363

6464

65-
def test_delete_table(capsys):
65+
@pytest.fixture
66+
def temporary_table():
67+
"""Fixture that returns a factory for tables that do not yet exist and
68+
will be automatically deleted after the test."""
69+
bigquery_client = bigquery.Client()
70+
dataset = bigquery_client.dataset(DATASET_ID)
71+
tables = []
72+
73+
def factory(table_name):
74+
new_table = dataset.table(table_name)
75+
if new_table.exists():
76+
new_table.delete()
77+
tables.append(new_table)
78+
return new_table
79+
80+
yield factory
81+
82+
for table in tables:
83+
if table.exists():
84+
table.delete()
85+
86+
87+
def test_create_table(temporary_table):
88+
new_table = temporary_table('test_create_table')
89+
snippets.create_table(DATASET_ID, new_table.name)
90+
assert new_table.exists()
91+
92+
93+
@pytest.mark.slow
94+
def test_copy_table(temporary_table):
95+
new_table = temporary_table('test_copy_table')
96+
snippets.copy_table(DATASET_ID, TABLE_ID, new_table.name)
97+
assert new_table.exists()
98+
99+
100+
def test_delete_table():
66101
# Create a table to delete
67102
bigquery_client = bigquery.Client()
68103
dataset = bigquery_client.dataset(DATASET_ID)

language/sentiment/README.txt

Lines changed: 0 additions & 27 deletions
This file was deleted.

language/sentiment/gcloud/.Python

Lines changed: 0 additions & 1 deletion
This file was deleted.

language/sentiment/gcloud/bin/python

-24.4 KB
Binary file not shown.

language/sentiment/gcloud/bin/python2

Lines changed: 0 additions & 1 deletion
This file was deleted.

language/sentiment/gcloud/bin/python2.7

Lines changed: 0 additions & 1 deletion
This file was deleted.

language/sentiment/gcloud/include/python2.7

Lines changed: 0 additions & 1 deletion
This file was deleted.

language/sentiment/out

Lines changed: 0 additions & 1 deletion
This file was deleted.

language/sentiment/sentiment_analysis.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,18 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
'''Demonstrates how to make a simple call to the Natural Language API'''
15+
1416
import argparse
1517
from googleapiclient import discovery
16-
import httplib2
1718
from oauth2client.client import GoogleCredentials
1819

1920

2021
def main(movie_review_filename):
2122
'''Run a sentiment analysis request on text within a passed filename.'''
2223

23-
credentials = GoogleCredentials.get_application_default().create_scoped(
24-
['https://www.googleapis.com/auth/cloud-platform'])
25-
http = httplib2.Http()
26-
credentials.authorize(http)
27-
28-
service = discovery.build('language', 'v1beta1', http=http)
24+
credentials = GoogleCredentials.get_application_default()
25+
service = discovery.build('language', 'v1beta1', credentials=credentials)
2926

3027
with open(movie_review_filename, 'r') as review_file:
3128
service_request = service.documents().analyzeSentiment(
@@ -38,18 +35,18 @@ def main(movie_review_filename):
3835
)
3936
response = service_request.execute()
4037

41-
try:
42-
polarity = response['documentSentiment']['polarity']
43-
magnitude = response['documentSentiment']['magnitude']
44-
except KeyError:
45-
print("The response did not contain the expected fields.")
46-
print('Sentiment: polarity of %s with magnitude of %s'
47-
% (polarity, magnitude))
38+
polarity = response['documentSentiment']['polarity']
39+
magnitude = response['documentSentiment']['magnitude']
40+
41+
print('Sentiment: polarity of {} with magnitude of {}'.format(
42+
polarity, magnitude))
4843
return 0
4944

5045

5146
if __name__ == '__main__':
52-
parser = argparse.ArgumentParser()
47+
parser = argparse.ArgumentParser(
48+
description=__doc__,
49+
formatter_class=argparse.RawDescriptionHelpFormatter)
5350
parser.add_argument(
5451
'movie_review_filename',
5552
help='The filename of the movie review you\'d like to analyze.')

speech/api-client/transcribe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ def main(speech_file):
6161
body={
6262
'config': {
6363
# There are a bunch of config options you can specify. See
64-
# https://goo.gl/EPjAup for the full list.
64+
# https://goo.gl/KPZn97 for the full list.
6565
'encoding': 'LINEAR16', # raw 16-bit signed LE samples
6666
'sampleRate': 16000, # 16 khz
67-
# See https://goo.gl/DPeVFW for a list of supported languages.
67+
# See https://goo.gl/A9KJ1A for a list of supported languages.
6868
'languageCode': 'en-US', # a BCP-47 language tag
6969
},
7070
'audio': {

speech/api-client/transcribe_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ def main(speech_file):
5858
body={
5959
'config': {
6060
# There are a bunch of config options you can specify. See
61-
# https://goo.gl/EPjAup for the full list.
61+
# https://goo.gl/KPZn97 for the full list.
6262
'encoding': 'LINEAR16', # raw 16-bit signed LE samples
6363
'sampleRate': 16000, # 16 khz
64-
# See https://goo.gl/DPeVFW for a list of supported languages.
64+
# See https://goo.gl/A9KJ1A for a list of supported languages.
6565
'languageCode': 'en-US', # a BCP-47 language tag
6666
},
6767
'audio': {

speech/grpc/transcribe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def main(input_uri, encoding, sample_rate):
5757
response = service.SyncRecognize(cloud_speech.SyncRecognizeRequest(
5858
config=cloud_speech.RecognitionConfig(
5959
# There are a bunch of config options you can specify. See
60-
# https://goo.gl/A6xv5G for the full list.
60+
# https://goo.gl/KPZn97 for the full list.
6161
encoding=encoding, # one of LINEAR16, FLAC, MULAW, AMR, AMR_WB
6262
sample_rate=sample_rate, # the rate in hertz
6363
# See
@@ -89,7 +89,7 @@ def _gcs_uri(text):
8989
'--encoding', default='FLAC', choices=[
9090
'LINEAR16', 'FLAC', 'MULAW', 'AMR', 'AMR_WB'],
9191
help='How the audio file is encoded. See {}#L67'.format(PROTO_URL))
92-
parser.add_argument('--sample_rate', default=16000)
92+
parser.add_argument('--sample_rate', type=int, default=16000)
9393

9494
args = parser.parse_args()
9595
main(args.input_uri, args.encoding, args.sample_rate)

0 commit comments

Comments
 (0)