Beispiel #1
0
async def get_house(house_id, world, *, tries=5) -> House:
    """Returns a dictionary containing a house's info, a list of possible matches or None.

    If world is specified, it will also find the current status of the house in that world."""
    if tries == 0:
        raise errors.NetworkError(f"get_house({house_id},{world})")
    try:
        async with aiohttp.ClientSession() as session:
            async with session.get(House.get_url_tibiadata(house_id, world)) as resp:
                content = await resp.text(encoding='ISO-8859-1')
                house = House.from_tibiadata(content)
    except aiohttp.ClientError:
        await asyncio.sleep(config.network_retry_delay)
        return await get_house(house_id, world, tries=tries - 1)
    return house
Beispiel #2
0
async def get_house(house_id, world, *, tries=5) -> House:
    """Returns a dictionary containing a house's info, a list of possible matches or None.

    If world is specified, it will also find the current status of the house in that world."""
    if tries == 0:
        raise errors.NetworkError(f"get_house({house_id},{world})")
    try:
        async with aiohttp.ClientSession() as session:
            async with session.get(House.get_url_tibiadata(house_id,
                                                           world)) as resp:
                content = await resp.text(encoding='ISO-8859-1')
                house = House.from_tibiadata(content)
    except aiohttp.ClientError:
        await asyncio.sleep(config.network_retry_delay)
        return await get_house(house_id, world, tries=tries - 1)
    return house
Beispiel #3
0
    def test_house_from_content(self):
        """Testing parsing a house"""
        content = self._load_resource(FILE_HOUSE_FULL)
        house = House.from_content(content)

        self.assertIsInstance(house, House)
        self.assertEqual(house.name, "Sorcerer's Avenue Labs 2e")
        self.assertEqual(house.beds, 1)
        self.assertTrue(house.rent, 715)
        self.assertEqual(house.status, HouseStatus.AUCTIONED)
        self.assertEqual(house.url, House.get_url(house.id, house.world))
        self.assertEqual(house.url_tibiadata, House.get_url_tibiadata(house.id, house.world))
        self.assertIsNone(house.owner)
        self.assertIsNone(house.owner_url)
        self.assertIsNotNone(house.highest_bidder)
        self.assertIsNotNone(house.highest_bidder_url)
        self.assertEqual(house.highest_bid, 0)

        house_json_raw = house.to_json()
        house_json = json.loads(house_json_raw)
        self.assertEqual(house.image_url, house_json["image_url"])