Skip to main content

Unoffical python client for TooGoodToGo API

Project description

Actions Status codecov PyPI version

tgtg-python

Python client that help you to talk with TooGoodToGo API.

Python version: 3.6, 3.7, 3.8, 3.9

Handle:

  • login (/api/auth/v1/loginByEmail)
  • list stores (/api/item/)
  • get a store (/api/item/:id)
  • set favorite (/api/item/:id/setFavorite)

Used by:

Install

pip install tgtg

Use it

Build the client

from tgtg import TgtgClient

# login with email and password
client = TgtgClient(email=your_email, password=your_password)

# or you can login with user_id and access_token
# (you can retrieve them from client after logged with email and password)
client = TgtgClient(access_token=your_access_token, user_id=your_user_id)

Get items

# You can then get some items, by default it will *only* get your favorites
client.get_items()

# To get items (not only your favorites) you need to provide location informations
client.get_items(
    favorites_only=False,
    latitude=48.126,
    longitude=-1.723,
    radius=10,
)
Example response
[
    {
        "item": {
            "item_id": "64346",
            "price": {"code": "EUR", "minor_units": 499, "decimals": 2},
            "sales_taxes": [],
            "tax_amount": {"code": "EUR", "minor_units": 0, "decimals": 2},
            "price_excluding_taxes": {"code": "EUR", "minor_units": 499, "decimals": 2},
            "price_including_taxes": {"code": "EUR", "minor_units": 499, "decimals": 2},
            "value_excluding_taxes": {
                "code": "EUR",
                "minor_units": 1500,
                "decimals": 2,
            },
            "value_including_taxes": {
                "code": "EUR",
                "minor_units": 1500,
                "decimals": 2,
            },
            "taxation_policy": "PRICE_INCLUDES_TAXES",
            "show_sales_taxes": False,
            "value": {"code": "EUR", "minor_units": 1500, "decimals": 2},
            "cover_picture": {
                "picture_id": "110628",
                "current_url": "https://images.tgtg.ninja/item/cover/2b69cbdd-43d3-4ade-bd51-50e338260859.jpg",
            },
            "logo_picture": {
                "picture_id": "110618",
                "current_url": "https://images.tgtg.ninja/store/fb893813-a775-4dec-ac7b-d4a7dd326fa8.png",
            },
            "name": "",
            "description": "Salva comida en Ecofamily Bufé y tu pack podrá contener: comidas caseras.",
            "can_user_supply_packaging": False,
            "packaging_option": "MUST_BRING_BAG",
            "collection_info": "",
            "diet_categories": [],
            "item_category": "MEAL",
            "badges": [
                {
                    "badge_type": "SERVICE_RATING_SCORE",
                    "rating_group": "LIKED",
                    "percentage": 93,
                    "user_count": 178,
                    "month_count": 5,
                }
            ],
            "favorite_count": 0,
            "buffet": False,
        },
        "store": {
            "store_id": "59949s",
            "store_name": "Ecofamily Bufé - Centro",
            "branch": "",
            "description": "",
            "tax_identifier": "",
            "website": "",
            "store_location": {
                "address": {
                    "country": {"iso_code": "ES", "name": "Spain"},
                    "address_line": "Av. de los Piconeros, S/N, 14001 Córdoba, España",
                    "city": "",
                    "postal_code": "",
                },
                "location": {"longitude": -4.776045, "latitude": 37.894249},
            },
            "logo_picture": {
                "picture_id": "110618",
                "current_url": "https://images.tgtg.ninja/store/fb893813-a775-4dec-ac7b-d4a7dd326fa8.png",
            },
            "store_time_zone": "Europe/Madrid",
            "hidden": False,
            "favorite_count": 0,
            "we_care": False,
        },
        "display_name": "Ecofamily Bufé - Centro",
        "pickup_location": {
            "address": {
                "country": {"iso_code": "ES", "name": "Spain"},
                "address_line": "Av. de los Piconeros, S/N, 14001 Córdoba, España",
                "city": "",
                "postal_code": "",
            },
            "location": {"longitude": -4.776045, "latitude": 37.894249},
        },
        "items_available": 0,
        "distance": 4241.995584076078,
        "favorite": True,
        "in_sales_window": False,
        "new_item": False,
    },
]

Get an item

(Using item_id from get_items response)

client.get_item(item_id=64346)
Example response
{
    "item": {
        "item_id": "64346",
        "price": {"code": "EUR", "minor_units": 499, "decimals": 2},
        "sales_taxes": [],
        "tax_amount": {"code": "EUR", "minor_units": 0, "decimals": 2},
        "price_excluding_taxes": {"code": "EUR", "minor_units": 499, "decimals": 2},
        "price_including_taxes": {"code": "EUR", "minor_units": 499, "decimals": 2},
        "value_excluding_taxes": {"code": "EUR", "minor_units": 1500, "decimals": 2},
        "value_including_taxes": {"code": "EUR", "minor_units": 1500, "decimals": 2},
        "taxation_policy": "PRICE_INCLUDES_TAXES",
        "show_sales_taxes": False,
        "value": {"code": "EUR", "minor_units": 1500, "decimals": 2},
        "cover_picture": {
            "picture_id": "110628",
            "current_url": "https://images.tgtg.ninja/item/cover/2b69cbdd-43d3-4ade-bd51-50e338260859.jpg",
        },
        "logo_picture": {
            "picture_id": "110618",
            "current_url": "https://images.tgtg.ninja/store/fb893813-a775-4dec-ac7b-d4a7dd326fa8.png",
        },
        "name": "",
        "description": "Salva comida en Ecofamily Buf\xc3\xa9 y tu pack podr\xc3\xa1 contener: comidas caseras.",
        "can_user_supply_packaging": False,
        "packaging_option": "MUST_BRING_BAG",
        "collection_info": "",
        "diet_categories": [],
        "item_category": "MEAL",
        "badges": [
            {
                "badge_type": "SERVICE_RATING_SCORE",
                "rating_group": "LIKED",
                "percentage": 93,
                "user_count": 178,
                "month_count": 5,
            }
        ],
        "favorite_count": 0,
        "buffet": False,
    },
    "store": {
        "store_id": "59949s",
        "store_name": "Ecofamily Buf\xc3\xa9 - Centro",
        "branch": "",
        "description": "",
        "tax_identifier": "",
        "website": "",
        "store_location": {
            "address": {
                "country": {"iso_code": "ES", "name": "Spain"},
                "address_line": "Av. de los Piconeros, S/N, 14001 C\xc3\xb3rdoba, Espa\xc3\xb1a",
                "city": "",
                "postal_code": "",
            },
            "location": {"longitude": -4.776045, "latitude": 37.894249},
        },
        "logo_picture": {
            "picture_id": "110618",
            "current_url": "https://images.tgtg.ninja/store/fb893813-a775-4dec-ac7b-d4a7dd326fa8.png",
        },
        "store_time_zone": "Europe/Madrid",
        "hidden": False,
        "favorite_count": 0,
        "items": [
            {
                "item": {
                    "item_id": "64346",
                    "price": {"code": "EUR", "minor_units": 499, "decimals": 2},
                    "sales_taxes": [],
                    "tax_amount": {"code": "EUR", "minor_units": 0, "decimals": 2},
                    "price_excluding_taxes": {
                        "code": "EUR",
                        "minor_units": 499,
                        "decimals": 2,
                    },
                    "price_including_taxes": {
                        "code": "EUR",
                        "minor_units": 499,
                        "decimals": 2,
                    },
                    "value_excluding_taxes": {
                        "code": "EUR",
                        "minor_units": 1500,
                        "decimals": 2,
                    },
                    "value_including_taxes": {
                        "code": "EUR",
                        "minor_units": 1500,
                        "decimals": 2,
                    },
                    "taxation_policy": "PRICE_INCLUDES_TAXES",
                    "show_sales_taxes": False,
                    "value": {"code": "EUR", "minor_units": 1500, "decimals": 2},
                    "cover_picture": {
                        "picture_id": "110628",
                        "current_url": "https://images.tgtg.ninja/item/cover/2b69cbdd-43d3-4ade-bd51-50e338260859.jpg",
                    },
                    "logo_picture": {
                        "picture_id": "110618",
                        "current_url": "https://images.tgtg.ninja/store/fb893813-a775-4dec-ac7b-d4a7dd326fa8.png",
                    },
                    "name": "",
                    "description": "Salva comida en Ecofamily Buf\xc3\xa9 y tu pack podr\xc3\xa1 contener: comidas caseras.",
                    "can_user_supply_packaging": False,
                    "packaging_option": "MUST_BRING_BAG",
                    "collection_info": "",
                    "diet_categories": [],
                    "item_category": "MEAL",
                    "badges": [
                        {
                            "badge_type": "SERVICE_RATING_SCORE",
                            "rating_group": "LIKED",
                            "percentage": 93,
                            "user_count": 178,
                            "month_count": 5,
                        }
                    ],
                    "favorite_count": 0,
                    "buffet": False,
                },
                "display_name": "Ecofamily Buf\xc3\xa9 - Centro",
                "pickup_location": {
                    "address": {
                        "country": {"iso_code": "ES", "name": "Spain"},
                        "address_line": "Av. de los Piconeros, S/N, 14001 C\xc3\xb3rdoba, Espa\xc3\xb1a",
                        "city": "",
                        "postal_code": "",
                    },
                    "location": {"longitude": -4.776045, "latitude": 37.894249},
                },
                "items_available": 0,
                "distance": 0.0,
                "favorite": True,
                "in_sales_window": False,
                "new_item": False,
            }
        ],
        "milestones": [
            {"type": "MEALS_SAVED", "value": "500"},
            {"type": "MONTHS_ON_PLATFORM", "value": "6"},
        ],
        "we_care": False,
    },
    "display_name": "Ecofamily Buf\xc3\xa9 - Centro",
    "pickup_location": {
        "address": {
            "country": {"iso_code": "ES", "name": "Spain"},
            "address_line": "Av. de los Piconeros, S/N, 14001 C\xc3\xb3rdoba, Espa\xc3\xb1a",
            "city": "",
            "postal_code": "",
        },
        "location": {"longitude": -4.776045, "latitude": 37.894249},
    },
    "items_available": 0,
    "distance": 0.0,
    "favorite": True,
    "in_sales_window": False,
    "new_item": False,
}

Set favorite

(Using item_id from get_items response)

# add favorite
client.set_favorite(item_id=64346, is_favorite=True)

# remove favorite
client.set_favorite(item_id=64346, is_favorite=False)

Developers

This project uses poetry so you will need to install poetry locally to use following commands.

pip install poetry --user
poetry install

This project uses pre-commit to format/check all the code before each commit automatically.

pip install pre-commit --user
pre-commit install

Run this command to run all tests:

make test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for tgtg, version 0.4.0
Filename, size File type Python version Upload date Hashes
Filename, size tgtg-0.4.0-py3-none-any.whl (5.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size tgtg-0.4.0.tar.gz (7.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page