Created
June 28, 2021 23:15
-
-
Save drewrothstein/12a2e8939a660aed6f3995143de834c6 to your computer and use it in GitHub Desktop.
Automower Cloud Function
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
import os | |
import sys | |
from flask import abort, escape | |
from google.cloud import firestore | |
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'sa_key.json' | |
def get_automower(): | |
db = firestore.Client() | |
key = db.collection(u'automower').document(u'automower') | |
snapshot = key.get() | |
return snapshot.to_dict()['message'] | |
def set_automower(message): | |
db = firestore.Client() | |
key = db.collection(u'automower').document(u'automower') | |
key.set({ | |
'message': message | |
}) | |
return 'Completed' | |
def main(request): | |
if request.method == 'GET': | |
return get_automower() | |
elif request.method == 'POST': | |
request_args = request.args | |
return set_automower(request_args['message']) | |
else: | |
return abort(405) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment