diff --git a/eggberg.py b/eggberg.py index b499969..41b2361 100755 --- a/eggberg.py +++ b/eggberg.py @@ -39,12 +39,13 @@ def unfurl(url): # inte borde göra så. Vi avkodar. title = html.unescape(ld['name']) image = ld['image'] - currency = ld['offers']['priceCurrency'] + offers = ld['offers'] + if not isinstance(offers, list): + offers = [offers] + currency = offers[0]['priceCurrency'] if currency == 'SEK': currency = 'kr' - # Formateringsinstruktionen "n" ger oss decimaltecken enligt aktuell - # locale. - price = f'{float(ld["offers"]["price"]):n}' + ' ' + currency + prices = [float(offer['price']) for offer in offers] return {'fallback': title + ' <' + url + '>', 'color': '#cf8e00', # ELAB-orange @@ -58,7 +59,9 @@ def unfurl(url): # innehåller något vettigt. # 'text': ld['description'], 'fields': [{'title': 'Pris', - 'value': price, + 'value': ' – '.join( + [f'{price:n} {currency}' for price in + list(dict.fromkeys([min(prices), max(prices)]))]), 'short': True}], # Visas som stor bild, vilket tar för mycket plats. # 'image_url': image,