Git Product home page Git Product logo

expiry-tracker-bot's Introduction

Grocery expiry tracker

API Endpoints

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

Tunneling with ngrok

Download ngrok to host the api from your computer.

./ngrok http 1337 -host-header='localhost:1337'

Notification using crontab

$ crontab -e

# Noify users of food expiring in the next 3 days
0 8 * * * python manage.py notify_users

Development

Uses the default Django development server.

  1. Rename .env.dev-sample to .env.dev.

  2. Update the environment variables in the docker-compose.yml and .env.dev files.

  3. 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.

Production

Uses gunicorn + nginx.

  1. Rename .env.prod-sample to .env.prod and .env.prod.db-sample to .env.prod.db. Update the environment variables.

  2. 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.

Supplementary files

  1. hfg.ipynb : Jupyter notebook for training the models
  2. telegram-bot/bot_script.py : Script for the Telegram Bot
  3. pushButtonToCapture.py Script for Raspberry Pi + Camera
  4. GroceryStoreDataset

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.