{"id":22769736,"url":"https://github.com/bfontaine/pykbg","last_synced_at":"2025-04-15T03:15:38.180Z","repository":{"id":62573802,"uuid":"202999089","full_name":"bfontaine/pykbg","owner":"bfontaine","description":"Python wrapper around Kelbongoo’s website","archived":false,"fork":false,"pushed_at":"2020-04-21T19:54:59.000Z","size":42,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T03:15:31.941Z","etag":null,"topics":["python-library"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bfontaine.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-18T12:16:27.000Z","updated_at":"2020-12-23T09:08:17.000Z","dependencies_parsed_at":"2022-11-03T17:30:32.140Z","dependency_job_id":null,"html_url":"https://github.com/bfontaine/pykbg","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfontaine%2Fpykbg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfontaine%2Fpykbg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfontaine%2Fpykbg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfontaine%2Fpykbg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bfontaine","download_url":"https://codeload.github.com/bfontaine/pykbg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248997084,"owners_count":21195799,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python-library"],"created_at":"2024-12-11T15:14:51.997Z","updated_at":"2025-04-15T03:15:38.164Z","avatar_url":"https://github.com/bfontaine.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyKbg\n\n**PyKbg** is a Python wrapper around [Kelbongoo][]’s website.\n\n[Kelbongoo]: https://www.kelbongoo.com\n\nKelbongoo is a [social economy][] company operating in the East of Paris,\nFrance. It sells products from small local producers (mostly located in the\n[Picardy][]), and is the only intermediary between the producer and the\nconsumer ([short food supply chain][sfsc]).\n\n[Picardy]: https://en.wikipedia.org/wiki/Picardy\n[sfsc]: https://en.wikipedia.org/wiki/Short_food_supply_chains\n[social economy]: https://en.wikipedia.org/wiki/Social_economy\n\n* [Install](#install)\n* [Usage](#usage)\n* [API Docs](#api-docs)\n* [Examples](#examples)\n* [Compatibility](#compatibility)\n* [Notes](#notes)\n\n## Install\n\n```shell\npip3 install kbg\n```\n\nThis requires Python ≥3.5.\n\n## Usage\nUse the `Kbg` class to initiate a connection:\n```python3\nfrom kbg import Kbg\n\nk = Kbg(your_email, your_password)\nprint(k.logged_in()) # True\n```\n\nSome general endpoints are available without connection:\n```python3\nfrom kbg import UnauthenticatedKbg\n\nk = UnauthenticatedKbg()\nprint(k.logged_in()) # False\n```\n\n## API Docs\n\n### `Kbg`\nThe `Kbg` constructor takes an email and a password. It raises an exception on\nfailed login.\n\n`Kbg` has all the endpoints `UnauthenticatedKbg` has, plus the following ones:\n\n#### `logged_in()`\nReturn a boolean indicating if the object is successfully connected.\n\n#### `get_customer_information()`\nGet some information as a `dict` about the consumer, including first and last\nname, email, phone, email settings.\n\n#### `get_customer_orders(page=1)`\nGet all the customer’s orders. This is a paginated endpoint. It returns a `dict` with an `orders` key as well as a `count`, `page` and `next_page` ones that you can use to get the next pages, if any.\n\n#### `get_all_customer_orders(full=False)`\nYield all the customer’s orders. This is a useful wrapper around\n`get_customer_order`.\n\nIf `full=True` is passed, call `get_customer_order` on each order to yield its\nfull information.\n\nNote that if all you want is the products’ full names, use\n`get_store_offer_dicts` as a lookup map instead of `full=True` to save\nunnecessary requests.\n\n#### `get_customer_order(order_id)`\nGet more information about a specific order (`dict`).\n\n### `UnauthenticatedKbg`\nThe `UnauthenticatedKbg` constructor doesn’t take any argument.\n\n#### `get_stores()`\nGet the list of stores (`list` of `dict`s).\n\n#### `get_store(store_id)`\nGet a single store (`dict`).\n\n#### `get_store_availabilities(store_id)`\nGet product availabilities at the given store for the current command window,\nas a map of product ids to units count.\n\n#### `get_store_offer(store_id, force=False)`\nGet the offer at a the given store (`dict`). This includes all products along\nwith their producers, categories, and families (subcategories).\n\nNote this method is cached; use `force=True` to force the API call.\n\n#### `get_store_offer_dicts(store_id, force=False)`\nEquivalent of `get_store_offer` that returns lookup `dict`s rather than lists\nof items.\n\n#### `get_store_status(store_id)`\nReturn a `dict` describing a store’s status.\n\n* `is_active` (`bool`): is the store active, i.e. are we in the timeframe for\n    orders?\n* `is_full` (`bool`): is the store full, i.e. it can’t take anymore orders?\n* `full_tags` (`str` `list`): what is full? Possible values: `\"ORDERS\"`, `\"SEC\"`, `\"FRAIS\"`\n\n### Examples\nCreate a simple connection:\n```python3\nfrom kbg import Kbg\n\nk = Kbg(\"your@email.com\", \"yourpassword\")\n```\n\n#### Compute your total spending\n```python3\ntotal_spent = 0\n\nfor order in k.get_all_customer_orders():\n    for product in order[\"products\"]:\n        total_spent += product[\"consumer_price\"]\n\n# get a price in euros rather than cents\ntotal_spent /= 100\n\nprint(\"You spent a total of %.2f€ at Kelbongoo!\" % total_spent)\n```\n\n#### Print your most-bought products\n```python3\nfrom collections import Counter\n\nmy_store = \"BOR\"\n\ntop_products = Counter()\ntop_producers = Counter()\nstore_products = k.get_store_offer_dicts(my_store)[\"products\"]\n\nfor order in k.get_all_customer_orders():\n    for product in order[\"products\"]:\n        product_id = product[\"id\"]\n        if product_id in store_products:\n            product = store_products[product_id]\n            top_products[product[\"product_name\"]] += 1\n            top_producers[product[\"producer_name\"]] += 1\n\nprint(\"Top products:\")\nfor product, n in top_products.most_common(5):\n    print(\"%3d - %s\" % (n, product))\n\nprint(\"\\nTop producers:\")\nfor producer, n in top_producers.most_common(5):\n    print(\"%3d - %s\" % (n, producer))\n```\n\n#### Find your beers coverage\n```python3\nmy_store = \"BOR\"\n\noffer = k.get_store_offer(my_store)\n\n# Get the id of the family 'Bières' (\"Beers\")\nbeer_family_id = None\nfor family in offer[\"families\"]:\n    if family[\"name\"] == \"Bières\":\n        beer_family_id = family[\"id\"]\n        break\nelse:\n    raise Exception(\"Can't find the beer family! :(\")\n\n# Collect all products in that family\nbeers = {}\nfor product in offer[\"products\"]:\n    if product[\"family_id\"] == beer_family_id:\n        beers[product[\"id\"]] = \"%-40s (%s)\" % (\n                product[\"product_name\"], product[\"producer_name\"])\n\nknown_beers = set()\n\n# Collect all *bought* products in that family\nfor order in k.get_all_customer_orders():\n    for product in order[\"products\"]:\n        product_id = product[\"id\"]\n        if product_id in beers:\n            known_beers.add(product_id)\n\nprint(\"You have tasted %d beers out of %d.\" % (len(known_beers), len(beers)))\nif len(known_beers) != len(beers):\n    print(\"Other beers you might want to try:\")\n    for beer_id, beer in beers.items():\n        if beer_id not in known_beers:\n            print(\"*\", beer)\n```\n\n## Compatibility\nThis library uses undocumented API endpoints, so it may break at any time.\n\n## Notes\nDon’t confuse KBG (Kelbongoo) with the [KGB](https://en.wikipedia.org/wiki/KGB).\n\nThe Kelbongoo API refers to stores as “locales”, using the first tree letters\nin upper-case as a primary key: `BOR` is Borrégo and `BIC` is Bichat, for\nexample.\n\nPrices are given in euro cents; you need to divide them by 100 to get the\nprice in euro: `\"consumer_price\": 221` means it’s something that costs €2.21.\n\nPlease throttle your requests to respect Kelbongoo’s servers.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbfontaine%2Fpykbg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbfontaine%2Fpykbg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbfontaine%2Fpykbg/lists"}