{ "info": { "author": "Baptiste Fontaine", "author_email": "b@ptistefontaine.fr", "bugtrack_url": null, "classifiers": [ "Environment :: Console", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# PyKbg\n\n**PyKbg** is a Python wrapper around [Kelbongoo][]\u2019s 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\n\n```shell\npip3 install kbg\n```\n\nThis requires Python \u22653.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### `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\u2019s 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\u2019s 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\u2019 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\u2019t take any argument.\n\n#### `get_stores()`\nGet the list of stores (`list` of `dict`s).\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### 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\u20ac 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\u00e8res' (\"Beers\")\nbeer_family_id = None\nfor family in offer[\"families\"]:\n if family[\"name\"] == \"Bi\u00e8res\":\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\u2019t confuse KBG (Kelbongoo) with [KGB](https://en.wikipedia.org/wiki/KGB).\n\nThe Kelbongoo API refers to stores as \u201clocales\u201d, using the first tree letters\nin upper-case as a primary key: `BOR` is Borr\u00e9go and `BIC` is Bichat, for\nexample.\n\nPrices are given in \u20acuro cents; you need to divide them by 100 to get the\nprice in \u20acuro: `\"consumer_price\": 221` means it\u2019s something that costs \u20ac2.21.\n\nPlease throttle your requests to respect Kelbongoo\u2019s servers.\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/bfontaine/pykbg", "keywords": "", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "kbg", "package_url": "https://pypi.org/project/kbg/", "platform": "", "project_url": "https://pypi.org/project/kbg/", "project_urls": { "Homepage": "https://github.com/bfontaine/pykbg" }, "release_url": "https://pypi.org/project/kbg/0.0.3/", "requires_dist": [ "requests" ], "requires_python": ">=3.5", "summary": "Python wrapper for the Kelbongoo website", "version": "0.0.3" }, "last_serial": 5700082, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "b1ea62c0d75bf6b5ce0851beeb6f93c9", "sha256": "4940dda1896cdfb3a08fd2a760be6376b71edec1c0bc1383163ea6c62d8f1688" }, "downloads": -1, "filename": "kbg-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "b1ea62c0d75bf6b5ce0851beeb6f93c9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 6270, "upload_time": "2019-08-18T21:41:56", "url": "https://files.pythonhosted.org/packages/bc/5d/de34fa787d4402d8166837a7d19a85ca9257342b0c555d04a0af20821ae3/kbg-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "72567507745f7d695136bf5f0fdad23a", "sha256": "8cf3ea77387f8aa214841a05a328acf8c0143dc13372df99149e775893498d2f" }, "downloads": -1, "filename": "kbg-0.0.1.tar.gz", "has_sig": false, "md5_digest": "72567507745f7d695136bf5f0fdad23a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 5435, "upload_time": "2019-08-18T21:42:00", "url": "https://files.pythonhosted.org/packages/aa/cc/ac6e79107a08840be2f427a95c31ac8d184ad6c73b136928569bceb6fc98/kbg-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "bdcf028ba614231e373e401fff7e0422", "sha256": "7ce187b3e7944c2656b55a76c940ffd46192b64ec3c1cbdfcc2fe9b467aacd1f" }, "downloads": -1, "filename": "kbg-0.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "bdcf028ba614231e373e401fff7e0422", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 6156, "upload_time": "2019-08-18T21:56:25", "url": "https://files.pythonhosted.org/packages/80/bc/08101ad20efae78467ddb19a9a8c644b4719ec59a8554f2130503509a2b0/kbg-0.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "32c1a4bfd5f3b4d61e3d3f88dd1b2daa", "sha256": "0fff6546b2377acd136347ca7b0a6fb06d541530deec0869505bcbf515242a85" }, "downloads": -1, "filename": "kbg-0.0.2.tar.gz", "has_sig": false, "md5_digest": "32c1a4bfd5f3b4d61e3d3f88dd1b2daa", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 5509, "upload_time": "2019-08-18T21:56:27", "url": "https://files.pythonhosted.org/packages/31/1f/97ebf6714f7b6bea92297674a1f3434417bdf2e7625186a0f04b8bea106e/kbg-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "7f4a8805e9a8b89d3e8062a5b9a1ecac", "sha256": "3d613487800dc3a55f8670916bd93471a856381729b34730e67bcd102597df2f" }, "downloads": -1, "filename": "kbg-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "7f4a8805e9a8b89d3e8062a5b9a1ecac", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 6943, "upload_time": "2019-08-19T19:54:01", "url": "https://files.pythonhosted.org/packages/a0/f3/66dae12e6f332a95811755c9fac7228239bae8f4c2b448b9c07f9d591fbf/kbg-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "316e9597d0ab5ed8628411eae859c5c5", "sha256": "12122d1736cd3966c40f3d8119459df6defdcf7be9e2e786693bc6d11a49ef6c" }, "downloads": -1, "filename": "kbg-0.0.3.tar.gz", "has_sig": false, "md5_digest": "316e9597d0ab5ed8628411eae859c5c5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 6508, "upload_time": "2019-08-19T19:54:04", "url": "https://files.pythonhosted.org/packages/f6/34/3829744aee02fa1ddb5c9011cc5e7a5d70cfb7a5628833e8f97b1bf09091/kbg-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7f4a8805e9a8b89d3e8062a5b9a1ecac", "sha256": "3d613487800dc3a55f8670916bd93471a856381729b34730e67bcd102597df2f" }, "downloads": -1, "filename": "kbg-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "7f4a8805e9a8b89d3e8062a5b9a1ecac", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5", "size": 6943, "upload_time": "2019-08-19T19:54:01", "url": "https://files.pythonhosted.org/packages/a0/f3/66dae12e6f332a95811755c9fac7228239bae8f4c2b448b9c07f9d591fbf/kbg-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "316e9597d0ab5ed8628411eae859c5c5", "sha256": "12122d1736cd3966c40f3d8119459df6defdcf7be9e2e786693bc6d11a49ef6c" }, "downloads": -1, "filename": "kbg-0.0.3.tar.gz", "has_sig": false, "md5_digest": "316e9597d0ab5ed8628411eae859c5c5", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5", "size": 6508, "upload_time": "2019-08-19T19:54:04", "url": "https://files.pythonhosted.org/packages/f6/34/3829744aee02fa1ddb5c9011cc5e7a5d70cfb7a5628833e8f97b1bf09091/kbg-0.0.3.tar.gz" } ] }