Skip to content

Commit a0cf359

Browse files
kchertenkonicainparthea
authored andcommitted
chore(samples): fix path to products files. (#296)
* fix: fix path to products files. * Fix path creation. Move gcs bucket creation logic to the function. Co-authored-by: nicain <nicholascain@google.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent f2f0136 commit a0cf359

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

generated_samples/interactive-tutorials/product/setup_product/products_create_gcs_bucket.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,27 @@
1313
# limitations under the License.
1414

1515
import datetime
16+
from pathlib import Path, PurePath
1617

1718
import google.auth
1819

1920
from setup_cleanup import create_bucket, upload_blob
2021

2122
project_id = google.auth.default()[1]
2223
timestamp_ = datetime.datetime.now().timestamp().__round__()
23-
bucket_name = f"{project_id}_products_{timestamp_}"
24+
BUCKET_NAME = f"{project_id}_products_{timestamp_}"
2425

25-
create_bucket(bucket_name)
26-
upload_blob(bucket_name, "../resources/products.json")
27-
upload_blob(bucket_name, "../resources/products_some_invalid.json")
2826

29-
print(f"\nThe gcs bucket {bucket_name} was created")
27+
def create_gcs_bucket(bucket_name=BUCKET_NAME):
28+
create_bucket(bucket_name)
29+
30+
path_to_resources_dir = PurePath(
31+
Path.home(), "cloudshell_open/python-retail/samples/interactive-tutorials/resources"
32+
)
33+
upload_blob(bucket_name, str(path_to_resources_dir / "products.json"))
34+
upload_blob(bucket_name, str(path_to_resources_dir / "products_some_invalid.json"))
35+
print(f"\nThe gcs bucket {bucket_name} was created")
36+
37+
38+
if __name__ == "__main__":
39+
create_gcs_bucket()

0 commit comments

Comments
 (0)