Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

docs(samples): remove project_number in interactive-tutorials #158

Merged
merged 4 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions samples/interactive-tutorials/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,12 @@ To run a code sample from the Cloud Shell, you need to be authenticated using th
export GOOGLE_APPLICATION_CREDENTIALS=~/key.json
```

### Set the GOOGLE_CLOUD_PROJECT_NUMBER and GOOGLE_CLOUD_PROJECT environment variables
### Set the GOOGLE_CLOUD_PROJECT environment variable

You will run the code samples in your own Google Cloud project. To use the **project_number** and **project_id** in every request to the Retail API, you should first specify them as environment variables.
You will run the code samples in your own Google Cloud project. To use the **project_id** in every request to the Retail API, you should first specify them as environment variables.

1. Find the project number and project ID in the Project Info card displayed on **Home/Dashboard**.
1. Find the project ID in the Project Info card displayed on **Home/Dashboard**.

1. Set the **project_number** with the following command:
```bash
export GOOGLE_CLOUD_PROJECT_NUMBER=<YOUR_PROJECT_NUMBER>
```
1. Set the **project_id** with the following command:
```bash
export GOOGLE_CLOUD_PROJECT=<YOUR_PROJECT_ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
## Required environment variables

To successfully import the catalog data for tests, the following environment variables should be set:
- GOOGLE_CLOUD_PROJECT_NUMBER
- GOOGLE_CLOUD_PROJECT
- BUCKET_NAME
- EVENTS_BUCKET_NAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
)
from google.protobuf.field_mask_pb2 import FieldMask

# Read the project number from the environment variable
# Read the project ID from the environment variable
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]

default_catalog = f"projects/{project_id}/locations/global/catalogs/default_catalog/branches/default_branch"
Expand Down
4 changes: 2 additions & 2 deletions samples/interactive-tutorials/search/search_simple_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

from google.cloud.retail import SearchRequest, SearchServiceClient

project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"]
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]


# get search service request:
def get_search_request(query: str):
default_search_placement = (
"projects/"
+ project_number
+ project_id
+ "/locations/global/catalogs/default_catalog/placements/default_search"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

from google.cloud.retail import SearchRequest, SearchServiceClient

project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"]
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]


# get search service request:
def get_search_request(query: str, condition: str, boost_strength: float):
default_search_placement = (
"projects/"
+ project_number
+ project_id
+ "/locations/global/catalogs/default_catalog/placements/default_search"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@

from google.cloud.retail import SearchRequest, SearchServiceClient

project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"]
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]


# get search service request:
def get_search_request(query: str, facet_key_param: str):
default_search_placement = (
"projects/"
+ project_number
+ project_id
+ "/locations/global/catalogs/default_catalog/placements/default_search"
)
# PUT THE INTERVALS HERE:
Expand Down
4 changes: 2 additions & 2 deletions samples/interactive-tutorials/search/search_with_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

from google.cloud.retail import SearchRequest, SearchServiceClient

project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"]
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]


# get search service request:
def get_search_request(query: str, _filter: str):
default_search_placement = (
"projects/"
+ project_number
+ project_id
+ "/locations/global/catalogs/default_catalog/placements/default_search"
)

Expand Down
4 changes: 2 additions & 2 deletions samples/interactive-tutorials/search/search_with_ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

from google.cloud.retail import SearchRequest, SearchServiceClient

project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"]
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]


# get search service request:
def get_search_request(query: str, order: str):
default_search_placement = (
"projects/"
+ project_number
+ project_id
+ "/locations/global/catalogs/default_catalog/placements/default_search"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

from google.cloud.retail import SearchRequest, SearchServiceClient

project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"]
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]


# get search service request:
def get_search_request(query: str, page_size: int, offset: int, next_page_token: str):
default_search_placement = (
"projects/"
+ project_number
+ project_id
+ "/locations/global/catalogs/default_catalog/placements/default_search"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from google.cloud.retail import SearchRequest, SearchServiceClient

project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"]
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]


# get search service request:
Expand All @@ -29,7 +29,7 @@ def get_search_request(
):
default_search_placement = (
"projects/"
+ project_number
+ project_id
+ "/locations/global/catalogs/default_catalog/placements/default_search"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from google.cloud.retail import ProductServiceClient
from google.cloud.storage.bucket import Bucket

project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"]
products_bucket_name = os.environ['BUCKET_NAME']
events_bucket_name = os.environ['EVENTS_BUCKET_NAME']
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
Expand All @@ -40,7 +39,7 @@
events_schema = "../resources/events_schema.json"

object_name = re.search('resources/(.*?)$', product_resource_file).group(1)
default_catalog = f"projects/{project_number}/locations/global/catalogs/default_catalog/branches/default_branch"
default_catalog = f"projects/{project_id}/locations/global/catalogs/default_catalog/branches/default_branch"

storage_client = storage.Client()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
from google.cloud.storage.bucket import Bucket


project_number = os.environ["GOOGLE_CLOUD_PROJECT_NUMBER"]
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
parthea marked this conversation as resolved.
Show resolved Hide resolved
parthea marked this conversation as resolved.
Show resolved Hide resolved
product_bucket_name = os.environ['BUCKET_NAME']
events_bucket_name = os.environ['EVENTS_BUCKET_NAME']

product_dataset = "products"
events_dataset = "user_events"

default_catalog = f"projects/{project_number}/locations/global/catalogs/default_catalog/branches/default_branch"
default_catalog = f"projects/{project_id}/locations/global/catalogs/default_catalog/branches/default_branch"

storage_client = storage.Client()

Expand Down