GET, POST /api/food
- CRUD on the list of food.
- When inserting new food into the api, the api will give an estimated expiry date based on the food inserted.
Examples:
POST
import requests
import json
url = 'http://localhost:1337/api/food/'
headers = {'Content-Type': 'application/json'}
data = {'name': 'Banana'}
data = json.dumps(data)
response = requests.post(url, data=data, headers=headers)
print(response.status_code) # 201 Created
print(response.json()) # dict of the new object
DELETE
import requests
import urllib.parse
url = 'http://localhost:1337/api/food/'
# Get the id of the food
params = {'search': 'Banana'}
response = requests.get(url, params=params)
print(response.json()) # [{'id': 2, 'name': 'Banana', 'expiry_date': '2020-03-25', 'image': None}, {'id': 4, 'name': 'Banana', 'expiry_date': '2020-03-25', 'image': None}]
id = response.json()[0]['id']
# Delete using the id
delete_url = urllib.parse.urljoin(url, str(id))
response = requests.delete(delete_url)
print(response.status_code) # 204 No Content
Download ngrok to host the api from your computer.
./ngrok http 1337 -host-header='localhost:1337'
$ crontab -e
# Noify users of food expiring in the next 3 days
0 8 * * * python manage.py notify_users
Uses the default Django development server.
-
Rename .env.dev-sample to .env.dev.
-
Update the environment variables in the docker-compose.yml and .env.dev files.
-
Build the images and run the containers:
$ docker-compose up -d --build
Test it out at http://localhost:8000. The "app" folder is mounted into the container and your code changes apply automatically.
Uses gunicorn + nginx.
-
Rename .env.prod-sample to .env.prod and .env.prod.db-sample to .env.prod.db. Update the environment variables.
-
Build the images and run the containers:
$ docker-compose -f docker-compose.prod.yml up -d --build
Test it out at http://localhost:1337. No mounted folders. To apply changes, the image must be re-built.
hfg.ipynb
: Jupyter notebook for training the modelstelegram-bot/bot_script.py
: Script for the Telegram BotpushButtonToCapture.py
Script for Raspberry Pi + Camera- GroceryStoreDataset