mirror of
https://github.com/Tech-Workers-Coalition-Italia/mobilizon-reshare.git
synced 2025-02-28 17:37:54 +01:00
fixed parsing bug
This commit is contained in:
parent
cf9ffd2149
commit
f35f3c78a9
@ -35,11 +35,13 @@ class TelegramFormatter(AbstractEventFormatter):
|
|||||||
_conf = ("publisher", "telegram")
|
_conf = ("publisher", "telegram")
|
||||||
|
|
||||||
def _validate_event(self, event: MobilizonEvent) -> None:
|
def _validate_event(self, event: MobilizonEvent) -> None:
|
||||||
|
|
||||||
description = event.description
|
description = event.description
|
||||||
if not (description and description.strip()):
|
if not (description and description.strip()):
|
||||||
self._log_error("No description was found", raise_error=InvalidEvent)
|
self._log_error("No description was found", raise_error=InvalidEvent)
|
||||||
|
|
||||||
def _validate_message(self, message: str) -> None:
|
def _validate_message(self, message: str) -> None:
|
||||||
|
|
||||||
if (
|
if (
|
||||||
len("".join(BeautifulSoup(message, "html.parser").findAll(text=True)))
|
len("".join(BeautifulSoup(message, "html.parser").findAll(text=True)))
|
||||||
>= 4096
|
>= 4096
|
||||||
@ -74,6 +76,7 @@ class TelegramFormatter(AbstractEventFormatter):
|
|||||||
tag.unwrap()
|
tag.unwrap()
|
||||||
# cleaning html trailing whitespace
|
# cleaning html trailing whitespace
|
||||||
for tag in html.findAll("a"):
|
for tag in html.findAll("a"):
|
||||||
|
if "href" in tag:
|
||||||
tag["href"] = tag["href"].replace(" ", "").strip().lstrip()
|
tag["href"] = tag["href"].replace(" ", "").strip().lstrip()
|
||||||
s = str(html)
|
s = str(html)
|
||||||
return re.sub(r"\n{2,}", "\n\n", s).strip() # remove multiple newlines
|
return re.sub(r"\n{2,}", "\n\n", s).strip() # remove multiple newlines
|
||||||
@ -103,7 +106,6 @@ class TelegramPlatform(AbstractPlatform):
|
|||||||
|
|
||||||
def _validate_response(self, res):
|
def _validate_response(self, res):
|
||||||
try:
|
try:
|
||||||
|
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
except requests.exceptions.HTTPError as e:
|
except requests.exceptions.HTTPError as e:
|
||||||
self._log_error(
|
self._log_error(
|
||||||
@ -113,6 +115,7 @@ class TelegramPlatform(AbstractPlatform):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
data = res.json()
|
data = res.json()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._log_error(
|
self._log_error(
|
||||||
f"Server returned invalid json data: {str(e)}",
|
f"Server returned invalid json data: {str(e)}",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user