From 48fdd37c032bfb2e53ca94ee5b48633a24e1e897 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sat, 7 Jul 2018 14:40:59 +0200 Subject: Reaktor url-title: show 450 chars max --- krebs/5pkgs/simple/Reaktor/plugins.nix | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'krebs') diff --git a/krebs/5pkgs/simple/Reaktor/plugins.nix b/krebs/5pkgs/simple/Reaktor/plugins.nix index 4a7917b68..3730b9e66 100644 --- a/krebs/5pkgs/simple/Reaktor/plugins.nix +++ b/krebs/5pkgs/simple/Reaktor/plugins.nix @@ -127,18 +127,17 @@ rec { from bs4 import BeautifulSoup try: - resp = urllib.request.urlopen(sys.argv[1]) + req = urllib.request.Request(sys.argv[1]) + req.add_header('user-agent', 'Reaktor-url-title') + resp = urllib.request.urlopen(req) if resp.headers['content-type'].find('text/html') >= 0: soup = BeautifulSoup(resp.read(16000), "lxml") title = soup.find('title').string - if title: - if len(title) > 450: - print('message to long, rest skipped') - elif len(title.split('\n')) > 5: - print('to many lines, skipped') - else: - print(title) + if len(title.split('\n')) > 5: + title = '\n'.join(title.split('\n')[:5]) + + print(title[:450]) else: cd_header = resp.headers['content-disposition'] print(cgi.parse_header(cd_header)[1]['filename']) -- cgit v1.2.3