@@ -346,39 +346,42 @@ def from_content(cls, content):
346346 InvalidContent
347347 If the content is not the house section on Tibia.com
348348 """
349- parsed_content = parse_tibiacom_content (content )
350- image_column , desc_column , * _ = parsed_content .find_all ('td' )
351- if "Error" in image_column .text :
352- return None
353- image = image_column .find ('img' )
354- for br in desc_column .find_all ("br" ):
355- br .replace_with ("\n " )
356- description = desc_column .text .replace ("\u00a0 " , " " ).replace ("\n \n " , "\n " )
357- lines = description .splitlines ()
358349 try :
359- name , beds , info , state , * _ = lines
360- except ValueError :
361- raise InvalidContent ("content does is not from the house section of Tibia.com" )
362-
363- house = cls (name .strip ())
364- house .image_url = image ["src" ]
365- house .id = int (id_regex .search (house .image_url ).group (1 ))
366- m = bed_regex .search (beds )
367- if m :
368- if m .group ("type" ).lower () in ["guildhall" , "clanhall" ]:
369- house .type = HouseType .GUILDHALL
370- else :
371- house .type = HouseType .HOUSE
372- house .beds = int (m .group ("beds" ))
373-
374- m = info_regex .search (info )
375- if m :
376- house .world = m .group ("world" )
377- house .rent = parse_tibia_money (m .group ("rent" ))
378- house .size = int (m .group ("size" ))
350+ parsed_content = parse_tibiacom_content (content )
351+ image_column , desc_column , * _ = parsed_content .find_all ('td' )
352+ if "Error" in image_column .text :
353+ return None
354+ image = image_column .find ('img' )
355+ for br in desc_column .find_all ("br" ):
356+ br .replace_with ("\n " )
357+ description = desc_column .text .replace ("\u00a0 " , " " ).replace ("\n \n " , "\n " )
358+ lines = description .splitlines ()
359+ try :
360+ name , beds , info , state , * _ = lines
361+ except ValueError :
362+ raise InvalidContent ("content does is not from the house section of Tibia.com" )
363+
364+ house = cls (name .strip ())
365+ house .image_url = image ["src" ]
366+ house .id = int (id_regex .search (house .image_url ).group (1 ))
367+ m = bed_regex .search (beds )
368+ if m :
369+ if m .group ("type" ).lower () in ["guildhall" , "clanhall" ]:
370+ house .type = HouseType .GUILDHALL
371+ else :
372+ house .type = HouseType .HOUSE
373+ house .beds = int (m .group ("beds" ))
379374
380- house ._parse_status (state )
381- return house
375+ m = info_regex .search (info )
376+ if m :
377+ house .world = m .group ("world" )
378+ house .rent = parse_tibia_money (m .group ("rent" ))
379+ house .size = int (m .group ("size" ))
380+
381+ house ._parse_status (state )
382+ return house
383+ except (ValueError , TypeError ) as e :
384+ raise InvalidContent ("content does not belong to a house page" , e )
382385 # endregion
383386
384387 def _parse_status (self , status ):
0 commit comments