utils package#
Submodules#
quick_reply module#
- pynani.utils.quick_reply.quick_buttons(buttons: List[str | int]) List[Dict]#
Prepares a list of quick reply buttons from a list of strings.
- Parameters:
buttons (List[Union[str, int]]) β A list of strings or integers representing the text for each quick reply button.
- Returns:
A list of dictionaries representing the quick reply buttons with their properties.
- Return type:
List
Example
>>> quick_buttons(["Hello", "World"]) [{'content_type': 'text', 'title': 'Hello', 'payload': '<POSTBACK_PAYLOAD>', 'image_url': None}, {'content_type': 'text', 'title': 'World', 'payload': '<POSTBACK_PAYLOAD>', 'image_url': None}] >>> quick_buttons([1, 2, 3]) [{'content_type': 'text', 'title': '1', 'payload': '<POSTBACK_PAYLOAD>', 'image_url': None}, {'content_type': 'text', 'title': '2', 'payload': '<POSTBACK_PAYLOAD>', 'image_url': None}, {'content_type': 'text', 'title': '3', 'payload': '<POSTBACK_PAYLOAD>', 'image_url': None}]
- pynani.utils.quick_reply.quick_image_buttons(buttons: List[str | int], images: List[str]) List[Dict]#
Prepares a list of quick reply buttons from a list of strings.
- Parameters:
buttons (List[str]) β A list of strings or integers representing the text for each quick reply button.
images (List[str]) β A list of strings representing the image URL for each quick reply button.
- Returns:
A list of dictionaries representing the quick reply buttons with their properties.
- Return type:
List
Example
>>> quick_image_buttons(["Hello", "World"], ["https://photos.com/hello.jpg", "https://photos.com/world.jpg"]) [{'content_type': 'text', 'title': 'Hello', 'payload': '<POSTBACK_PAYLOAD>', 'image_url': 'https://photos.com/hello.jpg'}, {'content_type': 'text', 'title': 'World', 'payload': '<POSTBACK_PAYLOAD>', 'image_url': 'https://photos.com/world.jpg'}]
- If a button does not have an image, the image URL should be None or an empty string.
>>> quick_image_buttons(["Hello", "World", "Yes"], ["https://photos.com/hello.jpg", "https://photos.com/world.jpg", None])
receipt module#
- pynani.utils.receipt.get_address(street_1: str, city: str, postal_code: str, state: str, country: str, street_2: str | None = None) Dict#
Constructs an address dictionary from the provided parameters.
- Parameters:
street_1 (str) β The first line of the street address.
city (str) β The city of the address.
postal_code (str) β The postal code of the address.
state (str) β The state or province of the address.
country (str) β The country of the address.
street_2 (Optional[str], optional) β The second line of the street address. Defaults to None.
- Returns:
A dictionary representing the address with its components.
- Return type:
Dict
Example
>>> get_address("123 Main St", "Springfield", "12345", "IL", "US", "Apt 1") {'street_1': '123 Main St', 'street_2': "Apt 1", 'city': 'Springfield', 'postal_code': '12345', 'state': 'IL', 'country': 'US'}
- Optional parameters can be omitted:
>>> get_address("123 Main St", "Springfield", "12345", "IL", "US") {'street_1': '123 Main St', 'street_2': None, 'city': 'Springfield', 'postal_code': '12345', 'state': 'IL', 'country': 'US'}
- pynani.utils.receipt.get_adjustments(*args: str | int | float) List[Dict]#
Constructs a list of adjustments from the provided arguments.
- Parameters:
*args (Union[str, int, float]) β A variable number of arguments, where each pair represents an adjustment name and amount.
- Returns:
A list of dictionaries, each representing an adjustment with its name and amount.
- Return type:
List[Dict]
Example
>>> get_adjustments("Discount", 10, "Tax", 20, "Shipping", 30) [{'name': 'Discount', 'amount': 10}, {'name': 'Tax', 'amount': 20}, {'name': 'Shipping', 'amount': 30}]
- pynani.utils.receipt.get_elements(title: str, price: float, subtitle: str | None = None, quantity: int | None = None, currency: str | None = 'USD', image_url: str | None = None) List[Dict]#
Constructs a list of elements from the provided parameters.
- Parameters:
title (str) β The title of the item.
price (float) β The price of the item.
subtitle (Optional[str], optional) β The subtitle of the item. Defaults to None.
quantity (Optional[int], optional) β The quantity of the item. Defaults to None.
currency (Optional[str], optional) β The currency of the item. Defaults to βUSDβ.
image_url (Optional[str], optional) β The URL of the itemβs image. Defaults to None.
- Returns:
A list of dictionaries representing the elements with their titles, prices, subtitles, quantities, currencies, and image URLs.
- Return type:
List
Example
>>> get_elements("T-Shirt", 20.0, "Blue", 2, "USD", "https://example.com/tshirt.jpg") [{'title': 'T-Shirt', 'subtitle': 'Blue', 'quantity': 2, 'price': 20.0, 'currency': 'USD', 'image_url': 'https://example.com/tshirt.jpg'}]
- Optional parameters can be omitted:
>>> get_elements("T-Shirt", 20.0) [{'title': 'T-Shirt', 'subtitle': None, 'quantity': None, 'price': 20.0, 'currency': 'USD', 'image_url': None}]
- pynani.utils.receipt.get_summary(total_cost: float, subtotal: float | None = None, shipping_cost: float | None = None, total_tax: float | None = None) Dict#
Constructs a summary dictionary from the provided parameters.
- Parameters:
total_cost (float) β The total cost of the order.
subtotal (Optional[float], optional) β The subtotal of the order. Defaults to None.
shipping_cost (Optional[float], optional) β The shipping cost of the order. Defaults to None.
total_tax (Optional[float], optional) β The total tax of the order. Defaults to None.
- Returns:
A dictionary representing the summary with its components.
- Return type:
Dict
Example
>>> get_summary(100.0, 90.0, 5.0, 5.0) {'subtotal': 90.0, 'shipping_cost': 5.0, 'total_tax': 5.0, 'total_cost': 100.0}
- Optional parameters can be omitted:
>>> get_summary(100.0) {'subtotal': None, 'shipping_cost': None, 'total_tax': None, 'total_cost': 100.0}