示例#1
0
async def get_pound_string():
    data = await _get_web_data(
        "https://www.chickensmoothie.com/poundandlostandfound.php"
    )  # Get web data
    if data[0]:  # If the data is valid
        text = data[1].xpath("//h2/text()")  # Get all H2 elements in the data
        if text[0] == "Pound & Lost and Found":
            pound_type = text[0]
            text = f"Sorry, both the {pound_type} are closed at the moment."
        else:
            pound_type = text[0][4:]
            try:
                text = (
                    library.multi_replace(
                        text[1],
                        {
                            "Sorry, the pound is closed at the moment.": "",
                            "Sorry, the Lost and Found is closed at the moment.": "",
                            "\n": "",
                            "\t": "",
                        },
                    )
                    + "."
                )  # Get opening text and remove extra formatting
            except IndexError:  # If there isn't any pound opening text
                text = f"""\
                {pound_type} is currently open!
                [Go {"claim an item" if pound_type == "Lost and Found" else "adopt a pet"} from the {pound_type}!](https://www.chickensmoothie.com/poundandlostandfound.php)"""
                text = textwrap.dedent(text)

        return pound_type, text
示例#2
0
def test_results():
    assert (
        multi_replace(
            "this is a long string\n with a new line",
            {"this": "This", "\n": "", "line": "line."},
        )
        == "This is a long string with a new line."
    )
示例#3
0
async def get_progeny(dragon_id1, dragon_id2, multiplier):
    parameters = {"id1": dragon_id1, "id2": dragon_id2}
    link = FlightRisingC.progeny_url + "?" + urlencode(parameters)
    outcomes = []

    for i in range(multiplier):
        data = await _get_web_data(link)
        if data[0]:
            if data[1].xpath("//img/@src"):
                image_links = data[1].xpath("//img/@src")
                outcomes.extend(image_links)
            else:
                text = multi_replace(data[1].text_content(), {"\n": "", "\t": ""})
                return str(text)
        await asyncio.sleep(0.1)

    return outcomes
示例#4
0
async def get_progeny(dragon_id1, dragon_id2, multiplier):
    parameters = {'id1': dragon_id1, 'id2': dragon_id2}
    link = FlightRisingC.progeny_url + '?' + urlencode(parameters)
    outcomes = []

    for i in range(multiplier):
        data = await _get_web_data(link)
        if data[0]:
            if data[1].xpath('//img/@src'):
                image_links = data[1].xpath('//img/@src')
                outcomes.extend(image_links)
            else:
                text = multi_replace(data[1].text_content(), {
                    '\n': '',
                    '\t': ''
                })
                return str(text)
        await asyncio.sleep(0.1)

    return outcomes
示例#5
0
 def rarity_link(self):
     filename = multi_replace(self.rarity.lower(), {'!': '', ' ': ''}) + '.png'
     return f'rarities/{filename}'
示例#6
0
 def rarity_link(self):
     filename = multi_replace(self.rarity.lower(), {
         "!": "",
         " ": ""
     }) + ".png"
     return f"rarities/{filename}"
示例#7
0
def test_results():
    assert multi_replace('this is a long string\n with a new line', {
        'this': 'This',
        '\n': '',
        'line': 'line.'
    }) == 'This is a long string with a new line.'