summaryrefslogtreecommitdiff
path: root/user-profiles
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2021-09-04 22:51:12 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2021-09-04 22:51:12 +0200
commit8536028d0c4a6906ab03f27bae4b038780697bc6 (patch)
treee21bcf97017304df67d8ab15aa07c368a9d2fa13 /user-profiles
parentb1fb537ef7207fb7c9d79d93f6ec02da4dee7ff1 (diff)
downloadnixos-8536028d0c4a6906ab03f27bae4b038780697bc6.tar
nixos-8536028d0c4a6906ab03f27bae4b038780697bc6.tar.gz
nixos-8536028d0c4a6906ab03f27bae4b038780697bc6.tar.bz2
nixos-8536028d0c4a6906ab03f27bae4b038780697bc6.tar.xz
nixos-8536028d0c4a6906ab03f27bae4b038780697bc6.zip
feeds: ...
Diffstat (limited to 'user-profiles')
-rw-r--r--user-profiles/feeds/imm-notmuch-insert.py19
-rw-r--r--user-profiles/feeds/module.nix2
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
7from email.message import EmailMessage 7from email.message import EmailMessage
8import configparser 8import configparser
9from os import environ 9from os import environ
10from datetime import *
11from dateutil.tz import *
10from dateutil.parser import isoparse 12from dateutil.parser import isoparse
13from html2text import html2text
11 14
12def main(): 15def 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