diff --git a/requirements.txt b/requirements.txt index 7a6977e..3217f13 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -appwrite \ No newline at end of file +appwrite diff --git a/src/main.py b/src/main.py index e8c9b14..c247243 100644 --- a/src/main.py +++ b/src/main.py @@ -1,82 +1,39 @@ - - from appwrite.client import Client from appwrite.services.users import Users -from appwrite.services.account import Account -from appwrite.services.databases import Databases from appwrite.exception import AppwriteException import os - - # This Appwrite function will be executed every time your function is triggered - - -def getBucks(userId): - ''' - userId => account.get_session('current') - ''' +def main(context): # You can use the Appwrite SDK to interact with other services # For this example, we're using the Users service client = ( Client() - .set_endpoint("https://cloud.appwrite.io/v1")#os.environ["APPWRITE_FUNCTION_API_ENDPOINT"] - .set_project("67609b010021900fc6e6") #os.environ["APPWRITE_FUNCTION_PROJECT_ID"] - .set_key("standard_a766a87da91bf274575dc294722839045769920a97a36eed295705391e817cad896c81e52c5dd654b6e7b3e6ec13bd16f3d607e416a543d5813d0aab7d7eae27af014a01aa74c503196056bd82eea708c844f1dcbba43f42d81a8a1c455727e6c93536fa6de367f8b92c23961ef1e9982f40c6b9caf1b46064515391dd1de308") + .set_endpoint(os.environ["APPWRITE_FUNCTION_API_ENDPOINT"]) + .set_project(os.environ["APPWRITE_FUNCTION_PROJECT_ID"]) + .set_key(context.req.headers["x-appwrite-key"]) ) users = Users(client) - databases = Databases(client) - account = Account(client) try: - #get users id - #passed in from function - - #find document with that name - doc= databases.get_document('6760b9c20030df251f1c','badgerBucks',userId) - #read the number of badgerBucks in that document - result = doc['badgerBucks'] - #return this - print(result) + response = users.list() + # Log messages and errors to the Appwrite Console + # These logs won't be seen by your end users + context.log("Total users: " + str(response["total"])) except AppwriteException as err: - print("there was an error") - - - -getBucks('hi') - -def createBucks(userId): - ''' - userId => account.get_session('current') - ''' - client = ( - Client() - .set_endpoint("https://cloud.appwrite.io/v1")#os.environ["APPWRITE_FUNCTION_API_ENDPOINT"] - .set_project("67609b010021900fc6e6") #os.environ["APPWRITE_FUNCTION_PROJECT_ID"] - .set_key("standard_a766a87da91bf274575dc294722839045769920a97a36eed295705391e817cad896c81e52c5dd654b6e7b3e6ec13bd16f3d607e416a543d5813d0aab7d7eae27af014a01aa74c503196056bd82eea708c844f1dcbba43f42d81a8a1c455727e6c93536fa6de367f8b92c23961ef1e9982f40c6b9caf1b46064515391dd1de308") - ) - users = Users(client) - database = Databases(client) - account = Account(client) - - database.create_document("6760b9c20030df251f1c","badgerBucks",userId,{userId,100}) - - - -def setBucks(number, userId): - ''' - userId => account.get_session('current') - ''' - client = ( - Client() - .set_endpoint("https://cloud.appwrite.io/v1")#os.environ["APPWRITE_FUNCTION_API_ENDPOINT"] - .set_project("67609b010021900fc6e6") #os.environ["APPWRITE_FUNCTION_PROJECT_ID"] - .set_key("standard_a766a87da91bf274575dc294722839045769920a97a36eed295705391e817cad896c81e52c5dd654b6e7b3e6ec13bd16f3d607e416a543d5813d0aab7d7eae27af014a01aa74c503196056bd82eea708c844f1dcbba43f42d81a8a1c455727e6c93536fa6de367f8b92c23961ef1e9982f40c6b9caf1b46064515391dd1de308") + context.error("Could not list users: " + repr(err)) + + # The req object contains the request data + if context.req.path == "/ping": + # Use res object to respond with text(), json(), or binary() + # Don't forget to return a response! + return context.res.text("Pong") + + return context.res.json( + { + "motto": "Build like a team of hundreds_", + "learn": "https://appwrite.io/docs", + "connect": "https://appwrite.io/discord", + "getInspired": "https://builtwith.appwrite.io", + } ) - database = Databases(client) - account = Account(client) - database.update_document("6760b9c20030df251f1c","badgerBucks",userId,{"username":userId, "badgerBucks": number}) - print("Success!") - -setBucks(99, "6761d9b300380c3f468d") -getBucks("6761d9b300380c3f468d") \ No newline at end of file