Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Starting work on OpenFoodFacts import

Harlene Samra35e2d2d738b9
diff --git a/extras/scripts/create_ingredients_from_foodfacts.py b/extras/scripts/create_ingredients_from_foodfacts.py
new file mode 100644
index 000000000..7b7c95394
--- /dev/null
+++ b/extras/scripts/create_ingredients_from_foodfacts.py
@@ -0,0 +1,18 @@
+from pymongo import MongoClient
+from wger.nutrition.models import Ingredient
+
+client = MongoClient('192.168.178.20', 27017)
+db = client.off
+
+# loop through each product and create Ingredient object
+# INGREDIENT = language, creation_date (auto to now), update_date (auto to now), name,
+ # energy, protein, fiber, carbs, sugar, fat, saturated, sodium, code, source_name, source_url,
+ # last_imported, common_name, image, category, brand
+
+
+for product in db.find({"lang": "de"}):
+ name = product.get('product_name')
+ print(name)
+# english, german, bulgarian, greek, spanish, russian, dutch, portuguese, czech, swedish, norwegian, french
+
+# Ingredient.create(blah)
\ No newline at end of file
diff --git a/extras/scripts/import_foodfacts.sh b/extras/scripts/import_foodfacts.sh
new file mode 100644
index 000000000..fb337cc15
--- /dev/null
+++ b/extras/scripts/import_foodfacts.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# -*- coding: utf-8 -*-
+
+wget https://static.openfoodfacts.org/data/openfoodfacts-mongodbdump.tar.gz
+
+tar xzvf openfoodfacts-mongodbdump.tar.gz
+docker pull mongo
+run --name wger_mongo --mount type=bind,source='"C:\Users\User\GitHub\openfoodfacts\dump"',target=/tmp/mongo_dump -p 27017:27017 -d mongo
+
+python create_ingredients_from_foodfacts.py
+
+rm openfoodfacts-mongodbdump.tar.gz
\ No newline at end of file
diff --git a/wger/nutrition/migrations/0008_remove_ingredient_updated.py b/wger/nutrition/migrations/0008_remove_ingredient_updated.py
new file mode 100644
index 000000000..e25feaa40
--- /dev/null
+++ b/wger/nutrition/migrations/0008_remove_ingredient_updated.py
@@ -0,0 +1,17 @@
+# Generated by Django 3.1.4 on 2020-12-12 21:38
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('nutrition', '0007_auto_20201211_0018'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='ingredient',
+ name='updated',
+ ),
+ ]
diff --git a/wger/nutrition/models.py b/wger/nutrition/models.py
index 11403083d..74d0587f9 100644
--- a/wger/nutrition/models.py
+++ b/wger/nutrition/models.py
@@ -397,8 +397,6 @@ class Ingredient(AbstractSubmissionModel, AbstractLicenseModel, models.Model):
last_imported = models.DateTimeField(default=timezone.now)
- updated = models.DateTimeField(default=timezone.now)
-
common_name = models.CharField(max_length=200,
verbose_name=_('Common name of product'),
null=True,