示例#1
0
 def get_fieldrow_dict(field_row: bs4.element.Tag) -> dict:
     keys = ['leider', 'contract', 'resultaat', 'door', 'uitkomst', 'punten', 'score']
     result_fieldrow_dict = OrderedDict([])
     fieldrow_columns = field_row.findChildren('td')
     for fieldrow_column, key in zip(fieldrow_columns, keys):
         result_fieldrow_dict[key] = get_clean_text_with_img_replaced_by_alt(fieldrow_column)
     return result_fieldrow_dict
示例#2
0
def parse_offers_table(
    table: bs4.element.Tag,
    skip_private: bool = True,
) -> list:

    rows = table.findChildren(['tr'])
    offers = []
    for row in rows[1:100]:
        selling = row.findChildren(['td'])[0]
        selling_items = parse_offer_items(selling)

        buying = row.findChildren(['td'])[1]
        buying_items = parse_offer_items(buying)

        quantity = row.findChildren(['td'])[2].text

        datetime = row.findChildren(['td'])[3].text
        datetime = dt.strptime(datetime, '%Y-%m-%d %H:%M:%S')

        user = row.findChildren(['td'])[5].text

        offer = [
            selling_items,
            buying_items,
            quantity,
            datetime,
            user,
        ]
        offers.append(offer)

    return offers
示例#3
0
def _render_image(image_elem: bs4.element.Tag) -> str:
    """
    Render custom <x-image> tag into an HTML string.

    `image_elem`: the tag as it exists in the current BS4 tree
    """
    path_elems = image_elem.findChildren('path', recursive=False)
    caption_elems = image_elem.findChildren('caption', recursive=False)
    alt_elems = image_elem.findChildren('alt', recursive=False)

    if len(path_elems) != 1:
        raise ValueError(
            '"x-image" tag does not have exactly one "path" specified')
    if len(caption_elems) == 2:
        raise ValueError('"x-image" tag has more than one "caption" specified')
    if len(alt_elems) == 2:
        raise ValueError('"x-image" tag has more than one "alt" specified')

    path = path_elems[0].contents[0]
    caption = caption_elems[0].contents[0] if caption_elems else None
    alt = alt_elems[0].contents[0] if alt_elems else ''

    # Render custom <figure> HTML
    return _create_figure_html(path, caption, alt)
示例#4
0
def parse_deaths_table(
    table: bs4.element.Tag,
    skip_private: bool = True,
) -> list:

    rows = table.findChildren(['tr'])
    characters = []

    for row in rows[1:100]:

        cols = row.find_all('td')
        cols = [element.text.strip() for element in cols]

        # We don't want to store/handle empty rows
        if cols[1] == 'Private':
            continue

        user = cols[1]
        base_fame = cols[3]
        total_fame = cols[4]
        maxed_stats = cols[6]
        killed_by = cols[7]

        datetime = cols[2].replace('T', ' ')[:-1]
        datetime = dt.strptime(datetime, '%Y-%m-%d %H:%M:%S')

        items = row.find_all('span', {'class': 'item'})
        items = [item['title'] for item in items]

        character = [
            user,
            datetime,
            base_fame,
            total_fame,
            items,
            maxed_stats,
            killed_by,
        ]
        characters.append(character)

    return characters