Skip to content

Commit

Permalink
chore(samples): fix path to products files. (#296)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored and dandhlee committed Dec 2, 2022
1 parent f2f0136 commit a0cf359
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,27 @@
# limitations under the License.

import datetime
from pathlib import Path, PurePath

import google.auth

from setup_cleanup import create_bucket, upload_blob

project_id = google.auth.default()[1]
timestamp_ = datetime.datetime.now().timestamp().__round__()
bucket_name = f"{project_id}_products_{timestamp_}"
BUCKET_NAME = f"{project_id}_products_{timestamp_}"

create_bucket(bucket_name)
upload_blob(bucket_name, "../resources/products.json")
upload_blob(bucket_name, "../resources/products_some_invalid.json")

print(f"\nThe gcs bucket {bucket_name} was created")
def create_gcs_bucket(bucket_name=BUCKET_NAME):
create_bucket(bucket_name)

path_to_resources_dir = PurePath(
Path.home(), "cloudshell_open/python-retail/samples/interactive-tutorials/resources"
)
upload_blob(bucket_name, str(path_to_resources_dir / "products.json"))
upload_blob(bucket_name, str(path_to_resources_dir / "products_some_invalid.json"))
print(f"\nThe gcs bucket {bucket_name} was created")


if __name__ == "__main__":
create_gcs_bucket()

0 comments on commit a0cf359

Please sign in to comment.