diff options
author | lassulus <lass@blue.r> | 2018-07-07 14:40:59 +0200 |
---|---|---|
committer | lassulus <lass@blue.r> | 2018-07-07 14:40:59 +0200 |
commit | 48fdd37c032bfb2e53ca94ee5b48633a24e1e897 (patch) | |
tree | d212910a394cda10d4b448f0f391aee922a72584 /krebs | |
parent | a25d95a06fefcff8b5034b01eec778bb15dbbdd6 (diff) |
Reaktor url-title: show 450 chars max
Diffstat (limited to 'krebs')
-rw-r--r-- | krebs/5pkgs/simple/Reaktor/plugins.nix | 15 |
1 files changed, 7 insertions, 8 deletions
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']) |