🏡 index : ~doyle/dave.git

author dave <dave@ip-172-26-11-212.eu-west-2.compute.internal> 2019-03-03 23:48:53.0 +00:00:00
committer dave <dave@ip-172-26-11-212.eu-west-2.compute.internal> 2019-03-03 23:49:11.0 +00:00:00
commit
2ec55d8216359b84b108d6d25a4e08483ad46d35 [patch]
tree
b2949059d9b4d2d97eee80e1e0c9d731d49b1f32
parent
3ea1f660120a17cb375a39e839e17d4872b3dbd2
download
2ec55d8216359b84b108d6d25a4e08483ad46d35.tar.gz

gfycat breaks me and i dont know why



Diff

 dave/modules/title.py | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/dave/modules/title.py b/dave/modules/title.py
index 04c3b97..9fcf8c1 100644
--- a/dave/modules/title.py
+++ b/dave/modules/title.py
@@ -19,6 +19,9 @@ def link_parse(bot, args, sender, source):
    titles = []

    for match in matches:
        if "gfycat" in match or ".webm" in match:
            continue

        if not dave.config.redis.exists("site:{}".format(match)):
            try:
                res = get(match, timeout=3,
@@ -32,15 +35,19 @@ def link_parse(bot, args, sender, source):
                    res.headers.get('Content-Type', ''):
                res.encoding = res.apparent_encoding

            soup = BeautifulSoup(res.text, "html.parser")
            title = soup.title.string

            if title is not None:
                title = re.sub(r"(\r?\n|\r| )+",
                               " ",
                               title.strip())
                title = title[:140] + (title[140:] and '...')
                dave.config.redis.setex("site:{}".format(match), 300, title)
            try:
                soup = BeautifulSoup(res.text, "html.parser")
                title = soup.title.string

                if title is not None:
                    title = re.sub(r"(\r?\n|\r| )+",
                                   " ",
                                   title.strip())
                    title = title[:140] + (title[140:] and '...')
                    dave.config.redis.setex("site:{}".format(match), 300, title)
            except BaseException as e:
                log.msg("Failed to grab title", e)
                return
        else:
            title = str(dave.config.redis.get("site:{}".format(match)), 'utf8')