aboutsummaryrefslogtreecommitdiffstats
path: root/python/test_gpg.py
blob: 6d8cdcd05d44270a2c7b1df7e4139c8ddfe119e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import gpg
from serenitas.utils.exchange import ExchangeMessage
import datetime

em = ExchangeMessage()
for msg in em.get_msgs(
    path=["SeleneOps", "Passport"],
    filters={"last_modification_time": datetime.date.today()},
):
    print(msg)
    for attach in msg.attachments:
        if attach.name == "Attachment1.pgp":
            try:
                with attach.fp as fp:
                    plaintext, result, verify_result = gpg.Context().decrypt(
                        fp.read(), passphrase="Serenitas1"
                    )
                    with open(
                        f"/home/serenitas/flint/{attach.last_modified_time.strftime('%Y%m%d')}_ISOSEL.csv",
                        "w",
                    ) as csvFile:
                        text = plaintext.decode("utf-8").replace("\t", ",")
                        csvFile.write(text)
                        break
            except gpg.errors.GPGMEError as e:
                print(e)