aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdaily-update.py5
-rw-r--r--email_helper.py25
-rwxr-xr-xwiki-from-email.py19
3 files changed, 36 insertions, 13 deletions
diff --git a/daily-update.py b/daily-update.py
index 165372a..6a52d16 100755
--- a/daily-update.py
+++ b/daily-update.py
@@ -1,8 +1,5 @@
#!/usr/bin/python3
-import smtplib
-import sys
-import time
import requests
from datetime import date
@@ -23,7 +20,7 @@ def get_weather():
def get_unread_reminders():
print("getting unread reminders")
subjects = email_helper.filter_unread("subject", "REMINDER:", "subject")
- subjects = [s[len("REMINDER: "):].strip() for s in subjects]
+ subjects = [s["subject"][len("REMINDER: "):].strip() for s in subjects]
if len(subjects) > 0:
reminder_html = "<h1>Reminders:</h1><ul>"
for s in subjects:
diff --git a/email_helper.py b/email_helper.py
index 84440ea..47bee20 100644
--- a/email_helper.py
+++ b/email_helper.py
@@ -51,6 +51,9 @@ def get_body(msg):
def get_from(msg):
return msg.get("From")
+def get_date(msg):
+ return msg.get("Date")
+
def get_content_type(msg):
return msg.get_content_type()
@@ -58,21 +61,25 @@ def set_unseen(imap, idx):
imap.store(idx, '-FLAGS', '\\SEEN')
def get_what(msg, what):
- if what == "subject":
- return get_subject(msg)
- elif what == "body":
- return get_body(msg)
- elif what == "from":
- return get_from(msg)
- elif what == "content_type":
- return get_content_type
+ ret = {}
+ if "subject" in what:
+ ret["subject"] = get_subject(msg)
+ if "body" in what:
+ ret["body"] = get_body(msg)
+ if "from" in what:
+ ret["from"] = get_from(msg)
+ if "content_type" in what:
+ ret["content_type"] = get_content_type(msg)
+ if "date" in what:
+ ret["date"] = get_date(msg)
+ return ret
def parse(imap, index, check_what, criteria, return_what):
res, msg = imap.fetch(index, "(RFC822)")
for response in msg:
if isinstance(response, tuple):
msg = email.message_from_bytes(response[1])
- if criteria in get_what(msg, check_what):
+ if criteria in get_what(msg, check_what)[check_what]:
return get_what(msg, return_what)
def filter_unread(check_what, criteria, return_what):
diff --git a/wiki-from-email.py b/wiki-from-email.py
new file mode 100755
index 0000000..a8b39e9
--- /dev/null
+++ b/wiki-from-email.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python3
+
+import email_helper
+import datetime
+import subprocess
+from config import config
+
+def get_wiki_emails():
+ bodies = email_helper.filter_unread("subject", "TODAY", "body date")
+ for b in bodies:
+ d = datetime.datetime.strptime(b["date"], "%a, %d %b %Y %H:%M:%S %z")
+ title = d.strftime("%B %-d")
+ path = d.strftime("%Y/%b/%d").lower()
+ exe = "/home/mark/projects/wikijscmd/main.py"
+ args = [exe, "create", path, title, b["body"]]
+ print(args)
+ subprocess.run(args)
+
+get_wiki_emails()