@@ -432,40 +432,37 @@ def from_content(cls, content):
432
432
InvalidContent
433
433
If the provided content is not the HTML content of the worlds section in Tibia.com
434
434
"""
435
- parsed_content = parse_tibiacom_content (content , html_class = "TableContentAndRightShadow" )
435
+ parsed_content = parse_tibiacom_content (content )
436
436
world_overview = WorldOverview ()
437
437
try :
438
- record_row , * rows = parsed_content .find_all ("tr" )
439
- m = record_regexp .search (record_row .text )
438
+ record_table , worlds_header_table , worlds_table , * tournament_tables \
439
+ = parsed_content .find_all ("table" , {"class" : "TableContent" })
440
+ m = record_regexp .search (record_table .text )
440
441
world_overview .record_count = parse_integer (m .group ("count" ))
441
442
world_overview .record_date = parse_tibia_datetime (m .group ("date" ))
442
- world_rows = rows
443
- world_overview ._parse_worlds (world_rows )
443
+ regular_world_rows = worlds_table .find_all ("tr" , attrs = {"class" : ["Odd" , "Even" ]})
444
+ world_overview ._parse_worlds (regular_world_rows )
445
+ if tournament_tables :
446
+ tournament_world_rows = tournament_tables [1 ].find_all ("tr" , attrs = {"class" : ["Odd" , "Even" ]})
447
+ world_overview ._parse_worlds (tournament_world_rows , True )
444
448
return world_overview
445
449
except (AttributeError , KeyError , ValueError ):
446
450
raise InvalidContent ("content does not belong to the World Overview section in Tibia.com" )
447
451
448
- def _parse_worlds (self , world_rows ):
452
+ def _parse_worlds (self , world_rows , tournament = False ):
449
453
"""Parses the world columns and adds the results to :py:attr:`worlds`.
450
454
451
455
Parameters
452
456
----------
453
457
world_rows: :class:`list` of :class:`bs4.Tag`
454
458
A list containing the rows of each world.
459
+ tournament: :class:`bool`
460
+ Whether these are tournament worlds or not.
455
461
"""
456
- tournament = False
457
462
for world_row in world_rows :
458
463
cols = world_row .find_all ("td" )
459
464
name = cols [0 ].text .strip ()
460
465
status = "Online"
461
- if len (cols ) == 1 and name == "Tournament Worlds" :
462
- tournament = True
463
- continue
464
- elif len (cols ) == 1 and name == "Regular Worlds" :
465
- tournament = False
466
- continue
467
- elif name == "World" :
468
- continue
469
466
online = parse_integer (cols [1 ].text .strip (), None )
470
467
if online is None :
471
468
online = 0
@@ -481,7 +478,6 @@ def _parse_worlds(self, world_rows):
481
478
m = battleye_regexp .search (battleye_icon ["onmouseover" ])
482
479
if m :
483
480
world .battleye_date = parse_tibia_full_date (m .group (1 ))
484
-
485
481
additional_info = cols [5 ].text .strip ()
486
482
world ._parse_additional_info (additional_info , tournament )
487
483
self .worlds .append (world )
0 commit comments