This commit is contained in:
Spectre 2024-09-02 16:56:54 +02:00
commit 223de1026e
3 changed files with 147 additions and 0 deletions

61
flake.lock generated Normal file
View file

@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1725194671,
"narHash": "sha256-tLGCFEFTB5TaOKkpfw3iYT9dnk4awTP/q4w+ROpMfuw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b833ff01a0d694b910daca6e2ff4a3f26dee478c",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

24
flake.nix Normal file
View file

@ -0,0 +1,24 @@
{
description = "Python development shell";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = {
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
python-packages = ps:
with ps; [
];
in {
devShells.default = pkgs.mkShell {
packages = with pkgs; [
bashInteractive
(python3.withPackages python-packages)
];
};
});
}

62
main.py Normal file
View file

@ -0,0 +1,62 @@
import datetime
import email
import email.header
import imaplib
import os
passw = os.getenv("IMAP_PASSWORD", "")
mail = os.getenv("IMAP_EMAIL", "")
domain = os.getenv("IMAP_SERVER", "imap.uni-potsdam.de")
folder = os.getenv("IMAP_FOLDER", "Uni Mail")
cutoff = os.getenv("IMAP_CUTOFF") or datetime.date.today() - datetime.timedelta(weeks=1)
def get_titles(cutoff):
with imaplib.IMAP4_SSL(domain) as imap:
imap.login(mail, passw)
status, [message_count] = imap.select(folder)
message_count = int(message_count)
m = message_count
date = datetime.date.today()
while date >= cutoff:
res, msg = imap.fetch(str(m), "(RFC822)") # fetches email using ID
for response in msg:
if isinstance(response, tuple):
msg = email.message_from_bytes(response[1])
subj = msg["Subject"]
subj = subj.split("[FSR MaPhy]", 1)[1]
decoded_subj, enc = email.header.decode_header(subj)[0]
if isinstance(decoded_subj, bytes):
decoded_subj = decoded_subj.decode(enc)
decoded_subj = decoded_subj.strip()
received, _ = email.header.decode_header(msg["Received"])[0]
received = received.split(";")[-1].strip()
date = datetime.datetime.strptime(received, "%a, %d %b %Y %X +0200").date()
yield date.isoformat(), decoded_subj
m -= 1
def generate_template(cutoff, template):
for date, subject in get_titles(cutoff):
yield template.format(date, subject)
if __name__ == "__main__":
template = r"""\textbf{{{}: {}}}
\begin{{itemize}}
\item
\end{{itemize}}"""
for t in generate_template(cutoff, template):
print(t)