pip install pygrocydm
Check Grocy API
https://blueblueblob.github.io/pygrocydm/
Import the package:
from pygrocydm import GrocyAPI
Obtain a grocy data manager instance:
gapi = GrocyAPI("https://example.com", "GROCY_API_KEY")
or
gapi = GrocyAPI("https://example.com", "GROCY_API_KEY", port = 9192, verify_ssl = True)
Product list (Generic entities API)
products = gapi.generic_entities().products()
products_list = products.list
for product in products_list:
print(vars(product))
if product.name == "Cookies":
product.delete()
if product.name == "Chocolate":
data = {}
data['name'] = "Choco"
product.edit(data)
else:
new_product = {}
new_product['name'] = 'Cookies'
new_product['location_id'] = 1
new_product['qu_id_purchase'] = 1
new_product['qu_id_stock'] = 1
new_product['qu_factor_purchase_to_stock'] = 1
new_product_id = products.add(new_product)
Recipes API :
recipes_api = gapi.recipes()
for recipe in recipes_api.fullfilment_list:
if recipe.recipe_id == 5:
recipe.add_not_fulfilled_products_to_shoppinglist()
else:
recipe.consume()
recipes_api.refresh()
Tasks API :
tasks_api = gapi.tasks()
for task in tasks_api.tasks_list:
if task.id == 5:
task.complete()
task.undo()
tasks_api.refresh()
System API :
system_api = gapi.system()
last_db_change = system_api.db_changed_time()