@@ -53,25 +53,25 @@ def from_url(cls, label: str, url: str) -> "Notice | None":
5353 table_content += "\t " .join (cols_text ) + "\n "
5454 table .decompose () # remove table from content
5555
56- title = cls .__get_title (cls , soup )
56+ title = cls .__get_title (soup )
5757 content = soup .find ("div" , attrs = {"class" : "field-item even" })
5858
59- prof = cls .__get_prof (cls , soup )
59+ prof = cls .__get_prof (soup )
6060
6161 if title is not None and content is not None :
62- title = title .get_text ()
63- content = content .get_text ()
62+ title_text = title .get_text ()
63+ content_text = content .get_text ()
6464
65- content = f"{ content .strip ()} \n { table_content } "
65+ content = f"{ content_text .strip ()} \n { table_content } "
6666 if prof is not None :
67- title = f"[{ prof } ]\n { title } "
67+ title_text = f"[{ prof } ]\n { title_text } "
6868
6969 else :
7070 return None
7171
72- title = f"\n { title } "
72+ title_text = f"\n { title_text } "
7373
74- return cls (label , title , content , url )
74+ return cls (label , title_text , content , url )
7575 except (
7676 requests .Timeout ,
7777 requests .ConnectionError ,
@@ -83,7 +83,8 @@ def from_url(cls, label: str, url: str) -> "Notice | None":
8383
8484 return None
8585
86- def __get_prof (self , soup : bs4 .BeautifulSoup ) -> str | None :
86+ @staticmethod
87+ def __get_prof (soup : bs4 .BeautifulSoup ) -> str | None :
8788 """Returns the prof of the notice
8889 Args:
8990 soup: BeautifulSoup object of the page
@@ -92,17 +93,23 @@ def __get_prof(self, soup: bs4.BeautifulSoup) -> str | None:
9293 """
9394 goto_prof_text = "Vai alla scheda del prof. "
9495 prof = soup .find ("a" , text = lambda text : text and goto_prof_text in text )
95- return prof and prof .get_text ().replace (goto_prof_text , "" )
96+ if isinstance (prof , bs4 .Tag ):
97+ return prof .get_text ().replace (goto_prof_text , "" )
98+ return None
9699
97- def __get_title (self , soup : bs4 .BeautifulSoup ) -> bs4 .BeautifulSoup | None :
100+ @staticmethod
101+ def __get_title (soup : bs4 .BeautifulSoup ) -> bs4 .Tag | None :
98102 """Returns the title of the notice
99103 Args:
100104 soup: BeautifulSoup object of the page
101105 Returns:
102106 the soup of the title
103107 """
104108 title = soup .find ("h1" , attrs = {"class" : "page-title" })
105- return title if title else soup .select_one ("section#content h1" )
109+ if isinstance (title , bs4 .Tag ):
110+ return title
111+ result = soup .select_one ("section#content h1" )
112+ return result if isinstance (result , bs4 .Tag ) else None
106113
107114 @property
108115 def formatted_url (self ) -> str :
0 commit comments