def __init__(self, player_uri, date=None): self.player_url = reconstruct_url_player(player_uri=player_uri, date=date) self.req = requests.get(self.player_url) assert self.req.status_code in [ 200 ], "[Html error] code %d" % self.req.status_code self.raw_data = self.req.text assert self.req.url == self.player_url, "[html ERROR] Your player not Found : url %s" % self.player_url self.soup_data = BeautifulSoup(self.raw_data, features="html.parser")
def __init__(self, date=None): if date: self.players_url = reconstruct_url_player("players/", date=date) + "&offset=%d" else: self.players_url = base_sofifa_url + "players?offset=%d" self.req = requests.get(self.players_url % 0) assert self.req.status_code in [ 200 ], "[Html error] code %d" % self.req.status_code assert self.req.url == self.players_url % 0, "[html ERROR] Your player not Found : url %s" % ( self.players_url % 0) self.raw_data = self.req.text self.soup_data = BeautifulSoup(self.raw_data, features="html.parser") self.header = self.get_header()
def test_url_not_found(self): d = datetime(2006, 1, 1) with self.assertRaises(module.DateNotFound) as cm: module.reconstruct_url_player("player/158023/lionel-messi/", d)
def test_url_player_no_date(self): actual = module.reconstruct_url_player("player/158023/lionel-messi/") expected = "https://sofifa.com/player/158023/lionel-messi/" self.assertEqual(actual, expected)
def test_url_nearest(self): d = datetime(2019, 4, 19) actual = module.reconstruct_url_player("player/158023/lionel-messi/", d) expected = "https://sofifa.com/player/158023/lionel-messi/?v=19&e=159432&set=true" self.assertEqual(actual, expected)