コード例 #1
0
ファイル: crawler.py プロジェクト: marcuxyz/tibia-crawler
class Crawler:
    def __init__(self, tibia_url, character, downloader):
        self.tibia_url = tibia_url
        self.downlaoder = downloader
        self.parser = Parser()
        self.get_tibia_information(character)

    def get_tibia_information(self, character):
        character_url = urljoin(self.tibia_url,
                                "community/?subtopic=characters")
        params = self.config_params(character)
        response = self.downlaoder.post(character_url, data=params)

        if self.parser.character_not_found(response.text):
            parsed = self.parser.parse(response.text)
            self.save_data(parsed.__dict__)
            return parsed

    def config_params(self, character):
        return {"name": character, "Submit.x": 0, "Submit.y": 0}

    def save_data(self, data):
        name = data.get("name")
        with open(f"tibia/database/{name}.json", "w", encoding="utf-8") as f:
            json.dump(data, f)
            print("Personagem salvo com sucesso!")
コード例 #2
0
ファイル: crawler.py プロジェクト: marcuxyz/tibia-crawler
 def __init__(self, tibia_url, character, downloader):
     self.tibia_url = tibia_url
     self.downlaoder = downloader
     self.parser = Parser()
     self.get_tibia_information(character)
コード例 #3
0
def testNotFound(snapshot, notFoundHtml):
    confirmation = Parser().characterNotFound(notFoundHtml)
    assert not confirmation == True
コード例 #4
0
def testExtractAccountStatus(snapshot, resumeHtml):
    parsed = BeautifulSoup(resumeHtml, "html.parser")
    text = Parser().extract_account_status(parsed)
    snapshot.assert_match(text)
コード例 #5
0
def testExtractDeaths(snapshot, resumeHtml):
    parsed = BeautifulSoup(resumeHtml, "html.parser")
    deaths = Parser().extract_deaths(parsed)
    for death in deaths:
        snapshot.assert_match(death)
コード例 #6
0
def testExtractGuildMembership(snapshot, resumeHtml):
    parsed = BeautifulSoup(resumeHtml, "html.parser")
    text = Parser().extract_guild_membership(parsed)
    snapshot.assert_match(text)
コード例 #7
0
def testExtractLastLogin(snapshot, resumeHtml):
    parsed = BeautifulSoup(resumeHtml, "html.parser")
    text = Parser().extract_last_login(parsed)
    snapshot.assert_match(text)
コード例 #8
0
def testExtractResidence(snapshot, resumeHtml):
    parsed = BeautifulSoup(resumeHtml, "html.parser")
    text = Parser().extract_residence(parsed)
    snapshot.assert_match(text)
コード例 #9
0
def testExtractAchivements(snapshot, resumeHtml):
    parsed = BeautifulSoup(resumeHtml, "html.parser")
    text = Parser().extract_achivement(parsed)
    snapshot.assert_match(text)
コード例 #10
0
def testExtractVocation(snapshot, resumeHtml):
    parsed = BeautifulSoup(resumeHtml, "html.parser")
    text = Parser().extract_vocation(parsed)
    snapshot.assert_match(text)
コード例 #11
0
ファイル: test_parser.py プロジェクト: marcuxyz/tibia-crawler
def test_not_found(snapshot, not_found_html):
    confirmation = Parser().character_not_found(not_found_html)
    assert not confirmation == True
コード例 #12
0
ファイル: test_parser.py プロジェクト: marcuxyz/tibia-crawler
def test_extract_level(snapshot, resume_html):
    parsed = BeautifulSoup(resume_html, "html.parser")
    text = Parser().extract_level(parsed)
    snapshot.assert_match(text)