1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-09-22 04:25:55 -04:00

Ignore bs4 warnings

These are triggered by false positives and get printed to screen when
running `toot curses`.
This commit is contained in:
Ivan Habunek 2019-02-13 13:38:37 +01:00
parent 7bcf868469
commit 0dfb04e9e3
No known key found for this signature in database
GPG Key ID: CDBD63C43A30BB95

View File

@ -4,6 +4,7 @@ import os
import re
import socket
import unicodedata
import warnings
from bs4 import BeautifulSoup
@ -17,7 +18,13 @@ def str_bool(b):
def get_text(html):
"""Converts html to text, strips all tags."""
text = BeautifulSoup(html.replace(''', "'"), "html.parser").get_text()
# Ignore warnings made by BeautifulSoup, if passed something that looks like
# a file (e.g. a dot which matches current dict), it will warn that the file
# should be opened instead of passing a filename.
with warnings.catch_warnings():
warnings.simplefilter("ignore")
text = BeautifulSoup(html.replace(''', "'"), "html.parser").get_text()
return unicodedata.normalize('NFKC', text)