commit a2fc7335296397a6bc2f784536a4ef3249f8441a Author: The Creature Conservancy Date: Fri Feb 28 22:22:20 2025 -0500 bump diff --git a/plant_backend/__pycache__/main.cpython-312.pyc b/plant_backend/__pycache__/main.cpython-312.pyc new file mode 100644 index 0000000..919962c Binary files /dev/null and b/plant_backend/__pycache__/main.cpython-312.pyc differ diff --git a/plant_backend/log_file b/plant_backend/log_file new file mode 100644 index 0000000..d70f151 --- /dev/null +++ b/plant_backend/log_file @@ -0,0 +1,14 @@ +[21:50:26] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/server.py:83} INFO - Started server process [1815517] +[21:50:26] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/lifespan/on.py:48} INFO - Waiting for application startup. +[21:50:26] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/lifespan/on.py:62} INFO - Application startup complete. +[21:50:29] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/server.py:263} INFO - Shutting down +[21:50:29] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/lifespan/on.py:67} INFO - Waiting for application shutdown. +[21:50:29] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/lifespan/on.py:76} INFO - Application shutdown complete. +[21:50:29] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/server.py:93} INFO - Finished server process [1815517] +[21:50:31] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/server.py:83} INFO - Started server process [1815525] +[21:50:31] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/lifespan/on.py:48} INFO - Waiting for application startup. +[21:50:31] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/lifespan/on.py:62} INFO - Application startup complete. +[21:50:43] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/server.py:263} INFO - Shutting down +[21:50:43] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/lifespan/on.py:67} INFO - Waiting for application shutdown. +[21:50:43] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/lifespan/on.py:76} INFO - Application shutdown complete. +[21:50:43] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/server.py:93} INFO - Finished server process [1815525] diff --git a/plant_backend/log_file_name.log b/plant_backend/log_file_name.log new file mode 100644 index 0000000..59ef046 --- /dev/null +++ b/plant_backend/log_file_name.log @@ -0,0 +1,7 @@ +[21:50:22] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/server.py:83} INFO - Started server process [1815494] +[21:50:22] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/lifespan/on.py:48} INFO - Waiting for application startup. +[21:50:22] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/lifespan/on.py:62} INFO - Application startup complete. +[21:50:25] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/server.py:263} INFO - Shutting down +[21:50:26] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/lifespan/on.py:67} INFO - Waiting for application shutdown. +[21:50:26] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/lifespan/on.py:76} INFO - Application shutdown complete. +[21:50:26] {/home/tcc/envs/creature_codex/lib/python3.12/site-packages/uvicorn/server.py:93} INFO - Finished server process [1815494] diff --git a/plant_backend/main.py b/plant_backend/main.py new file mode 100644 index 0000000..f226932 --- /dev/null +++ b/plant_backend/main.py @@ -0,0 +1,54 @@ +from fastapi import FastAPI, Request +from fastapi.middleware.cors import CORSMiddleware +import psycopg2 +import psycopg2.extras +import logging +from typing import Dict, Any +from datetime import datetime + +logger = logging.getLogger('uvicorn.error') +logger.setLevel(logging.DEBUG) + +app = FastAPI() +app.add_middleware( + CORSMiddleware, + allow_origins=["*"], # Allows all origins + allow_credentials=True, + allow_methods=["*"], # Allows all methods + allow_headers=["*"], # Allows all headers +) + +db_conn = psycopg2.connect(dbname='codices',user='postgres',password='1597') + +postgres_url = "http://localhost:5432" + +@app.get("/") +async def root(): + return {"message": "Hello World"} + +@app.get('/plants/all') +def get_plant_list(): + cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor) + cur.execute('select * from plants.watering_status') + results = [dict(x) for x in cur.fetchall()] + cur.close() + return results + + +@app.post('/plants/update') +def update_plant(data: Dict[str, Any]): + + flag_deleted = False + action = 'Watered' + if data['action'] == 'UNDO_WATER': + flag_deleted = True + + value_place = (data['plant_name'], data['plant_location'], action, datetime.now().date(), flag_deleted) + cur = db_conn.cursor(cursor_factory=psycopg2.extras.DictCursor) + cur.execute("INSERT INTO plants.care_transactions (plant_name, plant_location, action, record_date, flag_deleted) VALUES (%s, %s, %s, %s, %s)",value_place) + db_conn.commit() + cur.close() + # body = req.json() # Parse incoming JSON payload + # print(body) + return + \ No newline at end of file diff --git a/plant_codex b/plant_codex new file mode 160000 index 0000000..f0389ac --- /dev/null +++ b/plant_codex @@ -0,0 +1 @@ +Subproject commit f0389ac49aaaf6f97215a6b7eb468d01b72263f6