update
This commit is contained in:
@@ -57,3 +57,36 @@ class AnimalShelter(object):
|
|||||||
return data
|
return data
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(f"Error: {e}")
|
raise Exception(f"Error: {e}")
|
||||||
|
|
||||||
|
def update(self, *args, **kwargs):
|
||||||
|
criteria = kwargs.get('criteria', None)
|
||||||
|
update_one = kwargs.get('once', False)
|
||||||
|
update_type = kwargs.get('update_type', None)
|
||||||
|
data = kwargs.get('data', None)
|
||||||
|
|
||||||
|
|
||||||
|
if update_one:
|
||||||
|
try:
|
||||||
|
self.collection.update_one(criteria, {f'${update_type}': data})
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception(f"Error: {e}")
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
self.collection.update_many(criteria, {f'${update_type}': data})
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception(f'Error: {e}')
|
||||||
|
|
||||||
|
def delete(self, *args, **kwargs):
|
||||||
|
criteria = kwargs.get('criteria', None)
|
||||||
|
delete_one = kwargs.get('once', False)
|
||||||
|
|
||||||
|
if delete_one:
|
||||||
|
try:
|
||||||
|
self.collection.delete_one(criteria)
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception(f'Error: {e}')
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
self.collection.delete_many(criteria)
|
||||||
|
except Exception as e:
|
||||||
|
raise Exception(f'Error: {e}')
|
23
app/main.py
23
app/main.py
@@ -1,29 +1,10 @@
|
|||||||
from AnimalShelter import AnimalShelter
|
from AnimalShelter import AnimalShelter
|
||||||
test = AnimalShelter()
|
test = AnimalShelter()
|
||||||
|
|
||||||
test_criteria = {"breed": "Pit Bull Mix"}
|
test_criteria = {"breed": "Protogen"}
|
||||||
test_data = test.read(criteria=test_criteria)
|
test_data = test.read(criteria=test_criteria)
|
||||||
|
|
||||||
for object in test_data:
|
for object in test_data:
|
||||||
print(object)
|
print(object)
|
||||||
|
|
||||||
test_data = {
|
test.delete(criteria={"breed": "Protogen"}, once=True)
|
||||||
'rec_num': 10001,
|
|
||||||
'age_upon_outcome': '3 years',
|
|
||||||
'animal_id': 'FA69420',
|
|
||||||
'animal_type': 'Furry',
|
|
||||||
'breed': 'Protogen',
|
|
||||||
'color': 'Purple',
|
|
||||||
'date_of_birth': '1999-12-25',
|
|
||||||
'datetime': '2019-10-11 10:03:00',
|
|
||||||
'monthyear': '2019-10-11T10:03:00',
|
|
||||||
'name': '*Brex',
|
|
||||||
'outcome_subtype': 'Foster',
|
|
||||||
'outcome_type': 'Adoption',
|
|
||||||
'sex_upon_outcome': 'Male i think',
|
|
||||||
'location_lat': 30.7118766251975,
|
|
||||||
'location_long': -97.2999365773623,
|
|
||||||
'age_upon_outcome_in_weeks': 558.059821428571
|
|
||||||
}
|
|
||||||
|
|
||||||
test.create(test_data)
|
|
@@ -1,5 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
|
command: sh -c "while true; do echo hello; sleep 2; done"
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
|
Reference in New Issue
Block a user