Geoffrey-Bot/GeoffreyBot/GeoffreyApiHelper.py

44 lines
1.3 KiB
Python
Raw Normal View History

def formatted_item_listing(item):
return "{} {} for {}D".format(item["amount"], item["item_name"], item["price"])
def formatted_location(location):
if location["tunnel"] is not None:
tunnel = "**{}** ".format(location["tunnel"])
else:
tunnel = ""
return '**{}** @ **{}** {}Owner(s): **{}**'.format(location["name"], formatted_position(location), tunnel,
formatted_owners(location))
def formatted_tunnel(tunnel):
return '**{} {}**: {}'.format(tunnel["tunnel_direction"], tunnel["tunnel_number"], tunnel["location_name"])
def formatted_position(location):
return '(x={}, z={})'.format(location["x_coord"], location["z_coord"])
def formatted_shop(shop):
inventory = ""
for item in shop["items"]:
inventory = inventory + "\n" + (formatted_item_listing(item))
return formatted_location(shop) + inventory
def formatted_owners(location):
owner_list = ''
if "owner" in location:
if len(location["owner"]) == 0:
owner_list = location["owner"][0]["name"]
else:
owner_list = location["owner"][0]["name"]
for owner in location["owner"][1:]:
owner_list += ", " + owner["name"]
return owner_list