# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['tgtg']

package_data = \
{'': ['*']}

install_requires = \
['requests>=2.27.1,<3.0.0']

setup_kwargs = {
    'name': 'tgtg',
    'version': '0.13.2',
    'description': 'Unoffical python client for TooGoodToGo API',
    'long_description': '[![Actions Status](https://github.com/ahivert/tgtg-python/workflows/CI/badge.svg)](https://github.com/ahivert/tgtg-python/actions)\n[![codecov](https://codecov.io/gh/ahivert/tgtg-python/branch/master/graph/badge.svg)](https://codecov.io/gh/ahivert/tgtg-python)\n[![PyPI version](https://img.shields.io/pypi/v/tgtg?color=blue)](https://pypi.org/project/tgtg/)\n\n# tgtg-python\n\nPython client that help you to talk with [TooGoodToGo](https://toogoodtogo.com) API.\n\nPython version: 3.7+\n\nHandle:\n\n- create an account (`auth/vX/signUpByEmail`)\n- login (`/api/auth/vX/authByEmail`)\n- refresh token (`/api/auth/vX/token/refresh`)\n- list stores (`/api/item/`)\n- get a store (`/api/item/:id`)\n- set favorite (`/api/item/:id/setFavorite`)\n- get active orders (`/api/order/vX/active`)\n- get inactive orders (`/api/order/vX/inactive`)\n\n## Install\n\n```\npip install tgtg\n```\n\n## Use it\n\n### Retrieve tokens\n\nBuild the client with your email\n\n```python\nfrom tgtg import TgtgClient\n\nclient = TgtgClient(email="<your_email>")\ncredentials = client.get_credentials()\n```\n\nYou should receive an email from tgtg.\nThe will wait until you validate the login by clicking the link inside the email.\n\nOnce you clicked the link, you will get credentials and be able to use them\n\n```python\nprint(credentials)\n{\n    \'access_token\': \'<your_access_token>\',\n    \'refresh_token\': \'<your_refresh_token>\',\n    \'user_id\': \'<your_user_id>\',\n}\n```\n\n### Build the client from tokens\n\n```python\nfrom tgtg import TgtgClient\n\nclient = TgtgClient(access_token="<access_token>", refresh_token="<refresh_token>", user_id="<user_id>")\n\n```\n\n### Get items\n\n```python\n# You can then get some items, by default it will *only* get your favorites\nitems = client.get_items()\nprint(items)\n\n# To get items (not only your favorites) you need to provide location informations\nitems = client.get_items(\n    favorites_only=False,\n    latitude=48.126,\n    longitude=-1.723,\n    radius=10,\n)\nprint(items)\n```\n\n<details>\n    <summary>Example response</summary>\n\n```python\n[\n    {\n        "item": {\n            "item_id": "64346",\n            "price": {"code": "EUR", "minor_units": 499, "decimals": 2},\n            "sales_taxes": [],\n            "tax_amount": {"code": "EUR", "minor_units": 0, "decimals": 2},\n            "price_excluding_taxes": {"code": "EUR", "minor_units": 499, "decimals": 2},\n            "price_including_taxes": {"code": "EUR", "minor_units": 499, "decimals": 2},\n            "value_excluding_taxes": {\n                "code": "EUR",\n                "minor_units": 1500,\n                "decimals": 2,\n            },\n            "value_including_taxes": {\n                "code": "EUR",\n                "minor_units": 1500,\n                "decimals": 2,\n            },\n            "taxation_policy": "PRICE_INCLUDES_TAXES",\n            "show_sales_taxes": False,\n            "value": {"code": "EUR", "minor_units": 1500, "decimals": 2},\n            "cover_picture": {\n                "picture_id": "110628",\n                "current_url": "https://images.tgtg.ninja/item/cover/2b69cbdd-43d3-4ade-bd51-50e338260859.jpg",\n            },\n            "logo_picture": {\n                "picture_id": "110618",\n                "current_url": "https://images.tgtg.ninja/store/fb893813-a775-4dec-ac7b-d4a7dd326fa8.png",\n            },\n            "name": "",\n            "description": "Salva comida en Ecofamily Bufé y tu pack podrá contener: comidas caseras.",\n            "can_user_supply_packaging": False,\n            "packaging_option": "MUST_BRING_BAG",\n            "collection_info": "",\n            "diet_categories": [],\n            "item_category": "MEAL",\n            "badges": [\n                {\n                    "badge_type": "SERVICE_RATING_SCORE",\n                    "rating_group": "LIKED",\n                    "percentage": 93,\n                    "user_count": 178,\n                    "month_count": 5,\n                }\n            ],\n            "favorite_count": 0,\n            "buffet": False,\n        },\n        "store": {\n            "store_id": "59949s",\n            "store_name": "Ecofamily Bufé - Centro",\n            "branch": "",\n            "description": "",\n            "tax_identifier": "",\n            "website": "",\n            "store_location": {\n                "address": {\n                    "country": {"iso_code": "ES", "name": "Spain"},\n                    "address_line": "Av. de los Piconeros, S/N, 14001 Córdoba, España",\n                    "city": "",\n                    "postal_code": "",\n                },\n                "location": {"longitude": -4.776045, "latitude": 37.894249},\n            },\n            "logo_picture": {\n                "picture_id": "110618",\n                "current_url": "https://images.tgtg.ninja/store/fb893813-a775-4dec-ac7b-d4a7dd326fa8.png",\n            },\n            "store_time_zone": "Europe/Madrid",\n            "hidden": False,\n            "favorite_count": 0,\n            "we_care": False,\n        },\n        "display_name": "Ecofamily Bufé - Centro",\n        "pickup_location": {\n            "address": {\n                "country": {"iso_code": "ES", "name": "Spain"},\n                "address_line": "Av. de los Piconeros, S/N, 14001 Córdoba, España",\n                "city": "",\n                "postal_code": "",\n            },\n            "location": {"longitude": -4.776045, "latitude": 37.894249},\n        },\n        "items_available": 0,\n        "distance": 4241.995584076078,\n        "favorite": True,\n        "in_sales_window": False,\n        "new_item": False,\n    },\n]\n```\n\n</details>\n\n### Get an item\n\n_(Using item_id from get_items response)_\n\n```python\nitem = client.get_item(item_id=614318)\nprint(item)\n```\n\n<details>\n<summary>Example response</summary>\n\n```python\n{\n    "item": {\n        "item_id": "614318",\n        "sales_taxes": [{"tax_description": "TVA", "tax_percentage": 5.5}],\n        "tax_amount": {"code": "EUR", "minor_units": 13, "decimals": 2},\n        "price_excluding_taxes": {"code": "EUR", "minor_units": 236, "decimals": 2},\n        "price_including_taxes": {"code": "EUR", "minor_units": 249, "decimals": 2},\n        "value_excluding_taxes": {"code": "EUR", "minor_units": 0, "decimals": 2},\n        "value_including_taxes": {"code": "EUR", "minor_units": 0, "decimals": 2},\n        "taxation_policy": "PRICE_INCLUDES_TAXES",\n        "show_sales_taxes": False,\n        "cover_picture": {\n            "picture_id": "620171",\n            "current_url": "https://images.tgtg.ninja/item/cover/ac80c1b3-1386-46a8-ba80-c97b3a6e7e18.png",\n            "is_automatically_created": False,\n        },\n        "logo_picture": {\n            "picture_id": "622046",\n            "current_url": "https://images.tgtg.ninja/store/6280890a-729c-400b-89d8-8b6d5b6cc17b.png",\n            "is_automatically_created": False,\n        },\n        "name": "Panier petit déjeuner",\n        "description": "Sauvez un panier-surprise réalisé à partir des délicieux articles d\'un buffet petit déjeuner.",\n        "food_handling_instructions": "",\n        "can_user_supply_packaging": False,\n        "packaging_option": "BAG_ALLOWED",\n        "collection_info": "",\n        "diet_categories": [],\n        "item_category": "BAKED_GOODS",\n        "buffet": True,\n        "badges": [\n            {\n                "badge_type": "SERVICE_RATING_SCORE",\n                "rating_group": "LOVED",\n                "percentage": 96,\n                "user_count": 131,\n                "month_count": 6,\n            },\n            {\n                "badge_type": "OVERALL_RATING_TRUST_SCORE",\n                "rating_group": "LOVED",\n                "percentage": 90,\n                "user_count": 131,\n                "month_count": 6,\n            },\n        ],\n        "positive_rating_reasons": [\n            "POSITIVE_FEEDBACK_FRIENDLY_STAFF",\n            "POSITIVE_FEEDBACK_GREAT_QUANTITY",\n            "POSITIVE_FEEDBACK_QUICK_COLLECTION",\n            "POSITIVE_FEEDBACK_DELICIOUS_FOOD",\n            "POSITIVE_FEEDBACK_GREAT_VALUE",\n            "POSITIVE_FEEDBACK_GREAT_VARIETY",\n        ],\n        "average_overall_rating": {\n            "average_overall_rating": 4.520325203252033,\n            "rating_count": 123,\n            "month_count": 6,\n        },\n        "allergens_info": {"shown_on_checkout": False},\n        "favorite_count": 0,\n    },\n    "store": {\n        "store_id": "624740",\n        "store_name": "Hôtel Les Matins de Paris & Spa",\n        "branch": "",\n        "description": "Vous y êtes. Où ? À South Pigalle (Sopi pour les adeptes), au coeur d’une décontraction trendy.\\nVous en êtes : de ceux qui ont déniché un lieu joliment habité, là où se fredonne depuis tant de décennies des airs vivement enjoués. Parce que, pour la petite histoire, notre adresse fut dans les années 50\' 60\' le repaire des plus arty.\\nPile ici, le premier restaurant américain parisien créé par le fantaisiste Leroy Haynes attirait un heureux tohu-bohu, une kyrielle de musiciens, de Ray Charles à Marianne Faithfull…\\nAujourd\'hui, à vous d\'improviser ici un rendez-vous amical, à vous de composer là avec la paresse la plus joyeuse. Se mettre au voluptueux diapason du spa, suivre le rythme des conseils spontanés d’une équipe concernée sont aussi des moments pour vous écouter.\\nEntendez-vous la petite musique du lieu ? L\'âme des Matins de Paris donne assurément le bon tempo pour prendre ses quartiers, les plus inspirés. ",\n        "tax_identifier": "FR43552132029",\n        "website": "https://www.lesmatinsdeparis.com/",\n        "store_location": {\n            "address": {\n                "country": {"iso_code": "FR", "name": "France"},\n                "address_line": "3 Rue Clauzel, 75009 Paris, France",\n                "city": "",\n                "postal_code": "",\n            },\n            "location": {"longitude": 2.3393925, "latitude": 48.8788434},\n        },\n        "logo_picture": {\n            "picture_id": "622046",\n            "current_url": "https://images.tgtg.ninja/store/6280890a-729c-400b-89d8-8b6d5b6cc17b.png",\n            "is_automatically_created": False,\n        },\n        "store_time_zone": "Europe/Paris",\n        "hidden": False,\n        "favorite_count": 0,\n        "items": [\n            {\n                "item": {\n                    "item_id": "614318",\n                    "sales_taxes": [{"tax_description": "TVA", "tax_percentage": 5.5}],\n                    "tax_amount": {"code": "EUR", "minor_units": 13, "decimals": 2},\n                    "price_excluding_taxes": {\n                        "code": "EUR",\n                        "minor_units": 236,\n                        "decimals": 2,\n                    },\n                    "price_including_taxes": {\n                        "code": "EUR",\n                        "minor_units": 249,\n                        "decimals": 2,\n                    },\n                    "value_excluding_taxes": {\n                        "code": "EUR",\n                        "minor_units": 0,\n                        "decimals": 2,\n                    },\n                    "value_including_taxes": {\n                        "code": "EUR",\n                        "minor_units": 0,\n                        "decimals": 2,\n                    },\n                    "taxation_policy": "PRICE_INCLUDES_TAXES",\n                    "show_sales_taxes": False,\n                    "cover_picture": {\n                        "picture_id": "620171",\n                        "current_url": "https://images.tgtg.ninja/item/cover/ac80c1b3-1386-46a8-ba80-c97b3a6e7e18.png",\n                        "is_automatically_created": False,\n                    },\n                    "logo_picture": {\n                        "picture_id": "622046",\n                        "current_url": "https://images.tgtg.ninja/store/6280890a-729c-400b-89d8-8b6d5b6cc17b.png",\n                        "is_automatically_created": False,\n                    },\n                    "name": "Panier petit déjeuner",\n                    "description": "Sauvez un panier-surprise réalisé à partir des délicieux articles d\'un buffet petit déjeuner.",\n                    "food_handling_instructions": "",\n                    "can_user_supply_packaging": False,\n                    "packaging_option": "BAG_ALLOWED",\n                    "collection_info": "",\n                    "diet_categories": [],\n                    "item_category": "BAKED_GOODS",\n                    "buffet": True,\n                    "badges": [\n                        {\n                            "badge_type": "SERVICE_RATING_SCORE",\n                            "rating_group": "LOVED",\n                            "percentage": 96,\n                            "user_count": 131,\n                            "month_count": 6,\n                        },\n                        {\n                            "badge_type": "OVERALL_RATING_TRUST_SCORE",\n                            "rating_group": "LOVED",\n                            "percentage": 90,\n                            "user_count": 131,\n                            "month_count": 6,\n                        },\n                    ],\n                    "positive_rating_reasons": [\n                        "POSITIVE_FEEDBACK_FRIENDLY_STAFF",\n                        "POSITIVE_FEEDBACK_GREAT_QUANTITY",\n                        "POSITIVE_FEEDBACK_QUICK_COLLECTION",\n                        "POSITIVE_FEEDBACK_DELICIOUS_FOOD",\n                        "POSITIVE_FEEDBACK_GREAT_VALUE",\n                        "POSITIVE_FEEDBACK_GREAT_VARIETY",\n                    ],\n                    "average_overall_rating": {\n                        "average_overall_rating": 4.520325203252033,\n                        "rating_count": 123,\n                        "month_count": 6,\n                    },\n                    "favorite_count": 0,\n                },\n                "display_name": "Hôtel Les Matins de Paris & Spa (Panier petit déjeuner)",\n                "pickup_interval": {\n                    "start": "2022-11-04T11:00:00Z",\n                    "end": "2022-11-04T15:00:00Z",\n                },\n                "pickup_location": {\n                    "address": {\n                        "country": {"iso_code": "FR", "name": "France"},\n                        "address_line": "3 Rue Clauzel, 75009 Paris, France",\n                        "city": "",\n                        "postal_code": "",\n                    },\n                    "location": {"longitude": 2.3393925, "latitude": 48.8788434},\n                },\n                "purchase_end": "2022-11-04T15:00:00Z",\n                "items_available": 0,\n                "sold_out_at": "2022-11-03T17:11:32Z",\n                "distance": 0.0,\n                "favorite": True,\n                "in_sales_window": True,\n                "new_item": False,\n            }\n        ],\n        "milestones": [\n            {"type": "MEALS_SAVED", "value": "250"},\n            {"type": "MONTHS_ON_PLATFORM", "value": "6"},\n        ],\n        "we_care": False,\n        "distance": 0.0,\n        "cover_picture": {\n            "picture_id": "620171",\n            "current_url": "https://images.tgtg.ninja/item/cover/ac80c1b3-1386-46a8-ba80-c97b3a6e7e18.png",\n            "is_automatically_created": False,\n        },\n        "is_manufacturer": False,\n    },\n    "display_name": "Hôtel Les Matins de Paris & Spa (Panier petit déjeuner)",\n    "pickup_interval": {"start": "2022-11-04T11:00:00Z", "end": "2022-11-04T15:00:00Z"},\n    "pickup_location": {\n        "address": {\n            "country": {"iso_code": "FR", "name": "France"},\n            "address_line": "3 Rue Clauzel, 75009 Paris, France",\n            "city": "",\n            "postal_code": "",\n        },\n        "location": {"longitude": 2.3393925, "latitude": 48.8788434},\n    },\n    "purchase_end": "2022-11-04T15:00:00Z",\n    "items_available": 0,\n    "sold_out_at": "2022-11-03T17:11:32Z",\n    "distance": 0.0,\n    "favorite": True,\n    "in_sales_window": True,\n    "new_item": False,\n    "sharing_url": "https://share.toogoodtogo.com/download?locale=fr-FR",\n    "next_sales_window_purchase_start": "2022-11-04T15:17:00Z",\n}\n```\n\n</details>\n\n### Get active orders\n\n```python\nactive = client.get_active()\nprint(active)\n```\n\n### Get inactive orders\n\n```python\nclient.get_inactive(page=0, page_size=20)\n\n# returned object has `has_more` property if more results are available\n```\n\nTo e.g. sum up all orders you have ever made:\n\n```python\n    orders = []\n    page = 0\n    while inactive := client.get_inactive(page=page, page_size=200):\n        orders += inactive["orders"]\n        if not inactive["has_more"]:\n            break\n\n    redeemed_orders = [x for x in orders if x["state"] == "REDEEMED"]\n    redeemed_items = sum([x["quantity"] for x in redeemed_orders])\n\n    # if you bought in multiple currencies this will need improvements\n    money_spend = sum(\n        [\n            x["price_including_taxes"]["minor_units"]\n            / (10 ** x["price_including_taxes"]["decimals"])\n            for x in redeemed_orders\n        ]\n    )\n\n    print(f"Total numbers of orders: {len(orders)}")\n    print(f"Total numbers of picked up orders: {len(redeemed_orders)}")\n    print(f"Total numbers of items picked up: {redeemed_items}")\n    print(\n        f"Total money spend: ~{money_spend:.2f}{redeemed_orders[0][\'price_including_taxes\'][\'code\']}"\n    )\n```\n\n### Set favorite\n\n_(Using item_id from get_items response)_\n\n```python\n# add favorite\nclient.set_favorite(item_id=64346, is_favorite=True)\n\n# remove favorite\nclient.set_favorite(item_id=64346, is_favorite=False)\n```\n\n### Create an account\n\n```python\nfrom tgtg import TgtgClient\n\nclient = TgtgClient()\nclient.signup_by_email(email="<your_email>")\n\n# client is now ready to be used\n```\n\n## Developers\n\nThis project uses poetry so you will need to install poetry locally to use following\ncommands.\n\n```\npip install poetry --user\npoetry install\n```\n\nThis project uses [pre-commit](https://pre-commit.com/) to format/check all the\ncode before each commit automatically.\n\n```\npip install pre-commit --user\npre-commit install\n```\n\nRun this command to run all tests:\n\n```\nmake test\n```\n',
    'author': 'Anthony Hivert',
    'author_email': 'anthony.hivert@gmail.com',
    'maintainer': 'None',
    'maintainer_email': 'None',
    'url': 'https://github.com/ahivert/tgtg-python',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.7,<4.0',
}


setup(**setup_kwargs)
