An open API service indexing awesome lists of open source software.

https://github.com/nikhil25803/track-calories

Backend for calorie tracking application using NLP-powered Nutritionix API to fetch calories from the text. In this RESTful API, multiple-level authentication, SQLite DB, OAuth, etc. are implemented.
https://github.com/nikhil25803/track-calories

fastapi pytest python3 sqlite

Last synced: about 1 year ago
JSON representation

Backend for calorie tracking application using NLP-powered Nutritionix API to fetch calories from the text. In this RESTful API, multiple-level authentication, SQLite DB, OAuth, etc. are implemented.

Awesome Lists containing this project

README

          

## Tech Stack 🖥️

![Python](https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54) ![FastAPI](https://img.shields.io/badge/FastAPI-005571?style=for-the-badge&logo=fastapi) ![SQLite](https://img.shields.io/badge/sqlite-%2307405e.svg?style=for-the-badge&logo=sqlite&logoColor=white)

## Commands to set up the repo (dependencies etc.) 💁‍♂️

- Clone the working branch
Copy the URL of the forked repository and clone it, as of now it is as follows (may vary, please check once)

```bash
git clone https://github.com/nikhil25803/track-calories.git
```

- Change the directory

```bash
cd track-calories
```

- Download Virtualenv package

```bash
pip install virtualenv
```

- Create a virtual environment

```bash
python -m venv env
```

- Activate the virtual environment

```bash
source env/scripts/activate
```

- Install the dependencies

```powershell
pip install -r requirements.txt
```

- The project setup has been completed. Before running the server, make sure to add a `.env` file with the following contents

```
OAUTH2_SECRET_KEY =
ADMIN_USERNAME =
ADMIN_PASSWORD =
MANAGER_USERNAME =
MANAGER_PASSOWRD =
NUTRITIONIX_APIKEY =
NUTRITIONIX_APPID =
```

- OAUTH2_SECRET_KEY can be generated by running the command `openssl rand -hex 32`
- Add credentials of your choice for Admin and Managers which you will use to access admin and manager level endpoints
- `NUTRITIONIX_APIKEY` and `NUTRITIONIX_APPID` needs to be generated from **nutritionix.com**. You can get them [here](https://developer.nutritionix.com/admin/access_details)

## Commands to run the API server ⚡

```bash
python main.py
```

- You will find the server running on `http://127.0.0.1:8000/`.

- You can also route to `http://127.0.0.1:8000/docs` for a user-friendly UI provided by **SwaggerUI** to interact with endpoints

**Note**

- Running the server will make a `sqlite_database.db` locally for database operations
- To run the unit and e2e test, it is important first to run the server

## Commands to run the test suite 📟

- As the `/test` directory is in the root path. You can run the test suit by running the following command

```bash
pytest
```

> Just to remind | Adding the `.env` file with the requested field is important, else some endpoints may throw some error

---