コード例 #1
0
def parse_fighter_page(ref):
    # parse main info from Sherdog
    logger.info("Parsing Sherdog info for {}".format(ref))

    sherdog_page = _download_page(_sherdog_ref(ref))

    fighter_name = sherdog_page.body.find('span', attrs={'class': 'fn'}).text

    ufc_url = "http://www.ufc.com/fighter/" + fighter_name.strip().replace(
        " ", "-")
    wiki_url = "https://en.wikipedia.org/wiki/" + fighter_name.strip().replace(
        " ", "_")

    fighter_data = FighterData(sherdog_page, _download_page(wiki_url),
                               _download_page(ufc_url))

    # extract each field
    fighter = Fighter(ref=ref, name=fighter_name)
    fighter.country = fighter_data.extract(country_extractor)
    fighter.city = fighter_data.extract(city_extractor)
    fighter.birthday = fighter_data.extract(sherdog_birthday_extractor,
                                            wiki_birthday_extractor)
    fighter.height = fighter_data.extract(height_extractor)
    fighter.weight = fighter_data.extract(weight_extractor)
    fighter.reach = fighter_data.extract(wiki_reach_extractor,
                                         ufc_reach_extractor)
    fighter.specialization = fighter_data.extract(spec_extractor)

    fight_infos = _parse_fight_infos(ref, sherdog_page)
    return fighter, fight_infos
コード例 #2
0
ファイル: parser.py プロジェクト: Some1Nebo/ufcpy
def parse_fighter_page(ref):
    # parse main info from Sherdog
    logger.info("Parsing Sherdog info for {}".format(ref))

    sherdog_page = _download_page(_sherdog_ref(ref))

    fighter_name = sherdog_page.body.find('span', attrs={'class': 'fn'}).text

    ufc_url = "http://www.ufc.com/fighter/" + fighter_name.strip().replace(" ", "-")
    wiki_url = "https://en.wikipedia.org/wiki/" + fighter_name.strip().replace(" ", "_")

    fighter_data = FighterData(
            sherdog_page,
            _download_page(wiki_url),
            _download_page(ufc_url)
    )

    # extract each field
    fighter = Fighter(ref=ref, name=fighter_name)
    fighter.country = fighter_data.extract(country_extractor)
    fighter.city = fighter_data.extract(city_extractor)
    fighter.birthday = fighter_data.extract(sherdog_birthday_extractor, wiki_birthday_extractor)
    fighter.height = fighter_data.extract(height_extractor)
    fighter.weight = fighter_data.extract(weight_extractor)
    fighter.reach = fighter_data.extract(wiki_reach_extractor, ufc_reach_extractor)
    fighter.specialization = fighter_data.extract(spec_extractor)

    fight_infos = _parse_fight_infos(ref, sherdog_page)
    return fighter, fight_infos
コード例 #3
0
from storage.models.fight import Fight
from storage.models.fighter import Fighter

from storage import Session, init_db
from storage.models.event import Event

if __name__ == "__main__":
    init_db()
    session = Session()

    tagir = Fighter(name='Tagir', ref='/fighter/tagir-1001')
    session.add(tagir)

    sergey = Fighter(name='Sergey', ref='/fighter/sergey-1002')
    session.add(sergey)

    ufc01 = Event(name='UFC 01', ref='/event/ufc-01')
    session.add(ufc01)

    f1 = Fight(fighter1=tagir, fighter2=sergey, event=ufc01, outcome='Tagir crushed him')
    session.add(f1)

    # e1 = session.query(Event).filter_by(name='UFC 01').first()
    # print(e1.fights[0].first_fighter.name)

    #t = session.query(Fighter).filter_by(name='Tagir').first()
    session.commit()

    t = session.query(Fight).first()

    tagir.name = "TTT"