-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added new files to firestore folder #36
Changes from 1 commit
42403c3
1107ab9
029f216
f4b942f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#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 firestore_delete(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!') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some of the logs end with punctuation and some don't, best to be consistent |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Function dependencies, for example: | ||
# package>=version | ||
google-cloud-firestore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the package not available by default in the Cloud Functions environment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No it is needed to be mentioned in the requirements.txt file, else we get an error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Inline comments should start with space: https://peps.python.org/pep-0008/#inline-comments