diff --git a/README.md b/README.md new file mode 100644 index 0000000..aeb891c --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ + + +From the windows command line, execute the following two commands to install the libraries: + +``` +pip install pysondb +pip install fastapi +``` + + +To run this app, from wnidows command line, execute: +``` +fastapi dev --host 0.0.0.0 --port 8100 main.py +``` diff --git a/care_status.json b/care_status.json new file mode 100644 index 0000000..5343c18 --- /dev/null +++ b/care_status.json @@ -0,0 +1,60 @@ +{ + "data": [ + { + "name": "Gordie", + "got_prepped": false, + "was_fed": false, + "has_cleaned": false, + "has_leftovers": false, + "id": 642860791847515770 + }, + { + "name": "Ozzy", + "got_prepped": false, + "was_fed": false, + "has_cleaned": false, + "has_leftovers": false, + "id": 520275854060945539 + }, + { + "name": "Cuddles", + "got_prepped": false, + "was_fed": false, + "has_cleaned": false, + "has_leftovers": false, + "id": 910984427821348550 + }, + { + "name": "Kya", + "got_prepped": false, + "was_fed": false, + "has_cleaned": false, + "has_leftovers": false, + "id": 142082488335022425 + }, + { + "name": "Scooter", + "got_prepped": false, + "was_fed": false, + "has_cleaned": false, + "has_leftovers": false, + "id": 276233041724878775 + }, + { + "name": "Juju", + "got_prepped": false, + "was_fed": false, + "has_cleaned": false, + "has_leftovers": false, + "id": 812769644527389690 + }, + { + "name": "Wanda", + "got_prepped": false, + "was_fed": false, + "has_cleaned": false, + "has_leftovers": false, + "id": 128015503582002645 + } + ] +} \ No newline at end of file diff --git a/care_transactions.json b/care_transactions.json new file mode 100644 index 0000000..2f72f0a --- /dev/null +++ b/care_transactions.json @@ -0,0 +1 @@ +{"data": []} \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..20925b9 --- /dev/null +++ b/main.py @@ -0,0 +1,62 @@ +#Just some generic imports +from fastapi import FastAPI +from starlette.responses import FileResponse +from pysondb import db +from pydantic import BaseModel +from datetime import datetime + +app = FastAPI() + + +# Get handles to database +care_db_file_name = "care_status.json" +care_transactions_file_name = "care_transactions.json" + +status_db = db.getDb(care_db_file_name) +transactions_db = db.getDb(care_transactions_file_name) + + + +# Return a html located within the pages folder +@app.get("/") +def root(): + return FileResponse('pages/checkboxes_demo.html') + + +# Return data by just dumping the database content +@app.get('/data.json') +def get_data(): + all_rows = status_db.getAll() + print("hello!") + for x in all_rows: + del x['id'] + return {'result': all_rows} + + +# This is the "schema" of web request made back and forth between the frontend and backend +class UpdateRecordFeedSheet(BaseModel): + animal_name: str + column_name: str + value_set: bool + + + +# This updates a record +@app.post('/update') +def update_data(item: UpdateRecordFeedSheet): + + # Extract the needed values + animal_name = item.animal_name + column_name = item.column_name + value_set = item.value_set + + + #Find the row to update, and update the new value + row_to_update = status_db.reSearch('name',animal_name)[0] #Pick the first row of results. This isn't a proper database + status_db.updateById(row_to_update['id'], {column_name:value_set}) + + # Add what was done to the transactions database + transactions_db.add( {'name': animal_name, 'column_updated': column_name, 'value_set': value_set, 'timestamp':datetime.now().isoformat()}) + + + diff --git a/pages/checkboxes_demo.html b/pages/checkboxes_demo.html new file mode 100644 index 0000000..402eb02 --- /dev/null +++ b/pages/checkboxes_demo.html @@ -0,0 +1,95 @@ + + + + + + + +
+ + + + + diff --git a/prep_database.py b/prep_database.py new file mode 100644 index 0000000..8dc097b --- /dev/null +++ b/prep_database.py @@ -0,0 +1,39 @@ +# This generates database file + +from pysondb import db +import os + +care_db_file_name = "care_status.json" +care_transactions_file_name = "care_transactions.json" + + +# Clear out database files +def remove_file(file_name): + if os.path.exists(file_name): + os.remove(file_name) + + +remove_file(care_db_file_name) +remove_file(care_transactions_file_name) + + +# Recreate database files +status_db = db.getDb(care_db_file_name) +transactions_db = db.getDb(care_transactions_file_name) + + +#We need to create a database where the first column is the animal name, and the subsequent columns are whether the food was prepped, they were fed, house was cleaned, and whether they had leftovers + +columns_to_add = ["got_prepped", "was_fed", "has_cleaned", "has_leftovers"] +animal_names = ["Gordie", "Ozzy", "Cuddles", "Kya", "Scooter", "Juju", "Wanda"] + + +# Go row by row, and add information +for animal in animal_names: + row_to_add = {'name': animal} + for column in columns_to_add: + row_to_add[column] = False #Set the "prepped/fed/cleaned/leftovers to false + + status_db.add(row_to_add) + +