@@ -466,25 +466,14 @@ def from_content(cls, content):
466466 parsed_content = parse_tibiacom_content (content )
467467 world_overview = WorldOverview ()
468468 try :
469- record_table , worlds_header_table , * worlds_tables \
470- = parsed_content .find_all ("table" , {"class" : "TableContent" })
471- m = record_regexp .search (record_table .text )
469+ records_table , * tables = parsed_content .find_all ("table" , {"class" : "TableContent" })
470+ m = record_regexp .search (records_table .text )
472471 world_overview .record_count = parse_integer (m .group ("count" ))
473472 world_overview .record_date = parse_tibia_datetime (m .group ("date" ))
474- if len (worlds_tables ) > 1 :
475- tournament_tables = worlds_tables [0 ]
476- worlds_table = worlds_tables [2 ]
477- else :
478- tournament_tables = None
479- worlds_table = worlds_tables [0 ]
480- regular_world_rows = worlds_table .find_all ("tr" , attrs = {"class" : ["Odd" , "Even" ]})
481- world_overview ._parse_worlds (regular_world_rows )
482- if tournament_tables :
483- tournament_world_rows = tournament_tables .find_all ("tr" , attrs = {"class" : ["Odd" , "Even" ]})
484- world_overview ._parse_worlds (tournament_world_rows , True )
473+ world_overview ._parse_worlds_tables (tables )
485474 return world_overview
486- except (AttributeError , KeyError , ValueError ):
487- raise InvalidContent ("content does not belong to the World Overview section in Tibia.com" )
475+ except (AttributeError , KeyError , ValueError ) as e :
476+ raise InvalidContent ("content does not belong to the World Overview section in Tibia.com" , e )
488477
489478 def _parse_worlds (self , world_rows , tournament = False ):
490479 """Parses the world columns and adds the results to :py:attr:`worlds`.
@@ -518,3 +507,21 @@ def _parse_worlds(self, world_rows, tournament=False):
518507 additional_info = cols [5 ].text .strip ()
519508 world ._parse_additional_info (additional_info , tournament )
520509 self .worlds .append (world )
510+
511+ def _parse_worlds_tables (self , tables ):
512+ """Parses the world columns and adds the results to :py:attr:`worlds`.
513+
514+ Parameters
515+ ----------
516+ world_rows: :class:`list` of :class:`bs4.Tag`
517+ A list containing the rows of each world.
518+ tournament: :class:`bool`
519+ Whether these are tournament worlds or not.
520+ """
521+ for title_table , worlds_table in zip (tables , tables [1 :]):
522+ title = title_table .text .lower ()
523+ regular_world_rows = worlds_table .find_all ("tr" , attrs = {"class" : ["Odd" , "Even" ]})
524+ self ._parse_worlds (regular_world_rows , "tournament" in title )
525+
526+
527+
0 commit comments