-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from Aniket-Parlikar/Firestore_delete_script
Added new files to firestore folder
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# The given script creates a CLoud Function to that is triggered when an image file is deleted from the street2sat-uploaded bucket | ||
# and then proceeds to delete the corresponding record from the Firestore DB. | ||
import logging | ||
from google.cloud import firestore | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
db = firestore.Client() | ||
|
||
def hello_gcs(event, context): | ||
"""Triggered by a change to a Cloud Storage bucket. | ||
Args: | ||
event (dict): Event payload. | ||
context (google.cloud.functions.Context): Metadata for the event. | ||
""" | ||
#Getting the image name | ||
img_path = event['name'] | ||
|
||
#Extracting the document name from the file path | ||
doc_ref=img_path.replace("/","-").split(".")[0] | ||
logging.info("The name of the document is "+doc_ref+".") | ||
|
||
#Getting the document reference | ||
doc = db.collection('street2sat').document(doc_ref) | ||
doc_check=doc.get() | ||
|
||
#Checking if the document reference exists in the collections and deleting it. | ||
if doc_check.exists: | ||
logger.info("The record associated with the image file exists in the Firestore DB.") | ||
logger.info("Deleting the given document.") | ||
doc.delete() | ||
logger.info("Document has been deleted.") | ||
else: | ||
logger.info('No such record associated with the image file exists in the Firestore DB!.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Function dependencies, for example: | ||
# package>=version | ||
google-cloud-firestore |