Skip to content

Commit

Permalink
Merge pull request #1505 from wger-project/feature/import-off-products
Browse files Browse the repository at this point in the history
Improve Open Food Facts import
  • Loading branch information
rolandgeider committed Nov 26, 2023
2 parents 0455290 + 73f045d commit ae7d049
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 236 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,6 @@ venv-wger
/wger/app_en.arb
/coverage.lcov
/media/
/static/
/extras/docker/open-food-facts/dump/*.tar.gz
/extras/docker/open-food-facts/dump/off/*
52 changes: 52 additions & 0 deletions extras/docker/open-food-facts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Import Open Food Facts products

This docker compose helps import or update products from the Open Food Facts
database into wger.

Note that the OFF database dump is very large, and you will need several times
this size available on your computer (tar.gz-file, extracted dump, mongo).

## 1

Download a current dump of their database

```shell
cd dump
wget https://static.openfoodfacts.org/data/openfoodfacts-mongodbdump.tar.gz
tar xzvf openfoodfacts-mongodbdump.tar.gz
```

## 2

Import the data into mongo.

Note that we are running this as a manual step since the import takes a while

```shell
docker compose up
docker compose exec mongodb mongorestore --username off --password off-wger -d admin -c products /dump/dump/off/products.bson
```

There is also an admin interface available at <http://localhost:8081>, log in with
these credentials:

* admin
* pass

## 3

Run the import script

```shell
python manage.py import-off-products
```

## 4

Don't forget to delete the dump and remove the containers if you love your
hard disk

```shell
docker compose down
rm dump -r openfoodfacts-mongodbdump.tar.gz dump/dump
```
20 changes: 20 additions & 0 deletions extras/docker/open-food-facts/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
mongodb:
image: mongo
ports:
- "27017:27017"
volumes:
- $PWD/dump:/dump
environment:
MONGO_INITDB_ROOT_USERNAME: off
MONGO_INITDB_ROOT_PASSWORD: off-wger

mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: off
ME_CONFIG_MONGODB_ADMINPASSWORD: off-wger
ME_CONFIG_MONGODB_URL: mongodb://off:off-wger@mongodb:27017/
Empty file.
234 changes: 0 additions & 234 deletions extras/scripts/create_ingredients_from_foodfacts.py

This file was deleted.

4 changes: 2 additions & 2 deletions wger/core/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,8 @@ def user_bodyweight(self, weight):
"""
if (
not WeightEntry.objects.filter(user=self.user).exists() or (
datetime.date.today() - WeightEntry.objects.filter(user=self.user).latest().date
> datetime.timedelta(days=3)
datetime.date.today() - WeightEntry.objects.filter(user=self.user).latest().date >
datetime.timedelta(days=3)
)
):
entry = WeightEntry()
Expand Down
Loading

0 comments on commit ae7d049

Please sign in to comment.