98 lines
2.6 KiB
Python
98 lines
2.6 KiB
Python
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 '**{}** @ **{}** {}{}'.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, base_url):
|
|
shop_info_list = formatted_location_info(shop, base_url)
|
|
|
|
if len(shop["items"]) > 0:
|
|
shop_info_list.append("**Inventory:**")
|
|
for item in shop["items"]:
|
|
shop_info_list.append(formatted_item_listing(item))
|
|
|
|
return shop_info_list
|
|
|
|
|
|
def formatted_farm(farm, base_url):
|
|
farm_info_list = formatted_location_info(farm, base_url)
|
|
|
|
if len(farm["resources"]) > 0:
|
|
farm_info_list.append("**Produces:**")
|
|
for resource in farm["resources"]:
|
|
farm_info_list.append(resource["name"])
|
|
|
|
return farm_info_list
|
|
|
|
|
|
def formatted_market(market, base_url):
|
|
market_info_list = formatted_location_info(market, base_url)
|
|
|
|
if len(market["shops"]) > 0:
|
|
market_info_list.append("**Shops:**")
|
|
for shop in market["shops"]:
|
|
market_info_list.append(formatted_location(shop))
|
|
|
|
return market_info_list
|
|
|
|
|
|
def formatted_location_info(location, base_url):
|
|
info = []
|
|
|
|
info.append(formatted_location(location))
|
|
info.append(get_full_link(base_url, location["link"]))
|
|
|
|
return info
|
|
|
|
|
|
def formatted_town(town, base_url):
|
|
town_info_list = formatted_location_info(town, base_url)
|
|
|
|
if len(town["residents"]) > 0:
|
|
town_info_list.append("**Residents:**")
|
|
|
|
for resident in town["residents"]:
|
|
town_info_list.append(resident["name"])
|
|
|
|
return town_info_list
|
|
|
|
|
|
def formatted_owners(location):
|
|
owner_list = ''
|
|
if "owner" in location:
|
|
|
|
if len(location["owner"]) == 1:
|
|
owner_list = 'Owner: **{}**'
|
|
owner_list = owner_list.format(location["owner"][0]["name"])
|
|
else:
|
|
owner_list = 'Owners: **{}**'
|
|
|
|
owners = location["owner"][0]["name"]
|
|
for owner in location["owner"][1:3]:
|
|
owners += ", " + owner["name"]
|
|
|
|
owner_list = owner_list.format(owners)
|
|
|
|
return owner_list
|
|
|
|
|
|
def get_full_link(base_url, link):
|
|
return base_url + link
|