Files
digest_app/openfoodfact.py
2024-04-15 14:50:54 +05:30

23 lines
591 B
Python

import openfoodfacts
import json
# User-Agent is mandatory
api = openfoodfacts.API(user_agent="Digest/1.0")
# Search for pizza products
data = api.product.text_search("Rice Noodles")
# Create filename (adjust as needed)
filename = "pizza_products.json"
# Open the file in write mode (will create if non-existent)
with open(filename, "w") as json_file:
# Convert data to JSON string (ensure proper indentation)
json_string = json.dumps(data, indent=4)
# Write the JSON string to the file
json_file.write(json_string)
print(f"Pizza product data saved to '{filename}'.")