diff options
Diffstat (limited to 'user-profiles/feeds')
-rw-r--r-- | user-profiles/feeds/imm-notmuch-insert.py | 19 | ||||
-rw-r--r-- | user-profiles/feeds/module.nix | 2 |
2 files changed, 17 insertions, 4 deletions
diff --git a/user-profiles/feeds/imm-notmuch-insert.py b/user-profiles/feeds/imm-notmuch-insert.py index a2dd3cb0..ba29ce5b 100644 --- a/user-profiles/feeds/imm-notmuch-insert.py +++ b/user-profiles/feeds/imm-notmuch-insert.py | |||
@@ -7,7 +7,10 @@ from io import BytesIO | |||
7 | from email.message import EmailMessage | 7 | from email.message import EmailMessage |
8 | import configparser | 8 | import configparser |
9 | from os import environ | 9 | from os import environ |
10 | from datetime import * | ||
11 | from dateutil.tz import * | ||
10 | from dateutil.parser import isoparse | 12 | from dateutil.parser import isoparse |
13 | from html2text import html2text | ||
11 | 14 | ||
12 | def main(): | 15 | def main(): |
13 | notmuchConfig = configparser.ConfigParser() | 16 | notmuchConfig = configparser.ConfigParser() |
@@ -17,15 +20,25 @@ def main(): | |||
17 | 20 | ||
18 | msg = EmailMessage() | 21 | msg = EmailMessage() |
19 | authors = ', '.join(map(lambda author: author['name'], callbackMessage['feed_item']['authors'])) | 22 | authors = ', '.join(map(lambda author: author['name'], callbackMessage['feed_item']['authors'])) |
20 | msg['From'] = f"{callbackMessage['feed_definition']['title']} ({authors}) <imm@imm.invalid>" | 23 | if authors: |
24 | msg['From'] = f"{callbackMessage['feed_definition']['title']} ({authors}) <imm@imm.invalid>" | ||
25 | else: | ||
26 | msg['From'] = f"{callbackMessage['feed_definition']['title']} <imm@imm.invalid>" | ||
21 | msg['To'] = f"{notmuchConfig['user']['name']} <{notmuchConfig['user']['primary_email']}>" | 27 | msg['To'] = f"{notmuchConfig['user']['name']} <{notmuchConfig['user']['primary_email']}>" |
22 | msg['Subject'] = callbackMessage['feed_item']['title'] | 28 | msg['Subject'] = callbackMessage['feed_item']['title'] |
23 | msg['Item-Identifier'] = f"{callbackMessage['feed_item']['identifier']}@imm.invalid" | 29 | msg['Item-Identifier'] = f"{callbackMessage['feed_item']['identifier']}" |
24 | for link in callbackMessage['feed_item']['links']: | 30 | for link in callbackMessage['feed_item']['links']: |
25 | msg.add_header('Link', link['uri']) | 31 | msg.add_header('Link', link['uri']) |
32 | date = None | ||
26 | if 'date' in callbackMessage['feed_item']: | 33 | if 'date' in callbackMessage['feed_item']: |
27 | date = isoparse(callbackMessage['feed_item']['date']) | 34 | date = isoparse(callbackMessage['feed_item']['date']) |
28 | msg['Date'] = date.strftime('%a, %e %b %Y %T %z') | 35 | else: |
36 | date = datetime.now(tzlocal()) | ||
37 | msg['Date'] = date.strftime('%a, %e %b %Y %T %z') | ||
38 | |||
39 | msg.set_content(html2text(callbackMessage['feed_item']['content'])) | ||
40 | msg.add_alternative(callbackMessage['feed_item']['content'], subtype='html') | ||
41 | |||
29 | 42 | ||
30 | subprocess.run( | 43 | subprocess.run( |
31 | args=['notmuch', 'insert'], | 44 | args=['notmuch', 'insert'], |
diff --git a/user-profiles/feeds/module.nix b/user-profiles/feeds/module.nix index cf8ee99c..9116fa91 100644 --- a/user-profiles/feeds/module.nix +++ b/user-profiles/feeds/module.nix | |||
@@ -30,7 +30,7 @@ let | |||
30 | 30 | ||
31 | phases = [ "buildPhase" "checkPhase" "installPhase" "fixupPhase" ]; | 31 | phases = [ "buildPhase" "checkPhase" "installPhase" "fixupPhase" ]; |
32 | 32 | ||
33 | python = pkgs.python39.withPackages (ps: with ps; [ configparser dateutil ]); | 33 | python = pkgs.python39.withPackages (ps: with ps; [ configparser dateutil html2text ]); |
34 | 34 | ||
35 | nativeBuildInputs = with pkgs; [ makeWrapper ]; | 35 | nativeBuildInputs = with pkgs; [ makeWrapper ]; |
36 | 36 | ||