|
@@ -50,8 +50,8 @@ def fetch_and_seed():
|
|
|
for row in reader:
|
|
for row in reader:
|
|
|
if len(row) < 3: continue
|
|
if len(row) < 3: continue
|
|
|
|
|
|
|
|
- # In this dataset, index 1 is name
|
|
|
|
|
- name = row[1] if len(row) > 1 else row[0]
|
|
|
|
|
|
|
+ # In this dataset, index 0 is always the food name
|
|
|
|
|
+ name = row[0]
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
calories = float(get_val(row, ['calorie', 'energy']))
|
|
calories = float(get_val(row, ['calorie', 'energy']))
|
|
@@ -75,33 +75,30 @@ def fetch_and_seed():
|
|
|
if cursor.fetchone():
|
|
if cursor.fetchone():
|
|
|
continue
|
|
continue
|
|
|
|
|
|
|
|
- try:
|
|
|
|
|
- cursor.execute('''
|
|
|
|
|
- INSERT INTO foods (name, category, calories, protein_g, fat_g, carbs_g, fiber_g, sugar_g, sodium_mg, vitamin_a_iu, vitamin_c_mg, calcium_mg, iron_mg, potassium_mg, cholesterol_mg, source)
|
|
|
|
|
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
|
|
|
- ''', (
|
|
|
|
|
- name[:100],
|
|
|
|
|
- "Sourced Ingredient",
|
|
|
|
|
- calories,
|
|
|
|
|
- protein,
|
|
|
|
|
- fat,
|
|
|
|
|
- carbs,
|
|
|
|
|
- fiber,
|
|
|
|
|
- sugar,
|
|
|
|
|
- sodium_mg,
|
|
|
|
|
- vitamin_a,
|
|
|
|
|
- vitamin_c,
|
|
|
|
|
- calcium,
|
|
|
|
|
- iron,
|
|
|
|
|
- potassium,
|
|
|
|
|
- cholesterol,
|
|
|
|
|
- 'Sourced_CSV'
|
|
|
|
|
- ))
|
|
|
|
|
- count += 1
|
|
|
|
|
- if count >= 8000: # Seed max 8000 to keep it lightweight locally
|
|
|
|
|
- break
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- continue
|
|
|
|
|
|
|
+ cursor.execute('''
|
|
|
|
|
+ INSERT INTO foods (name, category, calories, protein_g, fat_g, carbs_g, fiber_g, sugar_g, sodium_mg, vitamin_a_iu, vitamin_c_mg, calcium_mg, iron_mg, potassium_mg, cholesterol_mg, source)
|
|
|
|
|
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
|
|
|
+ ''', (
|
|
|
|
|
+ name[:100],
|
|
|
|
|
+ "Sourced Ingredient",
|
|
|
|
|
+ calories,
|
|
|
|
|
+ protein,
|
|
|
|
|
+ fat,
|
|
|
|
|
+ carbs,
|
|
|
|
|
+ fiber,
|
|
|
|
|
+ sugar,
|
|
|
|
|
+ sodium_mg,
|
|
|
|
|
+ vitamin_a,
|
|
|
|
|
+ vitamin_c,
|
|
|
|
|
+ calcium,
|
|
|
|
|
+ iron,
|
|
|
|
|
+ potassium,
|
|
|
|
|
+ cholesterol,
|
|
|
|
|
+ 'Sourced_CSV'
|
|
|
|
|
+ ))
|
|
|
|
|
+ count += 1
|
|
|
|
|
+ if count >= 8000:
|
|
|
|
|
+ break
|
|
|
|
|
|
|
|
conn.commit()
|
|
conn.commit()
|
|
|
conn.close()
|
|
conn.close()
|