update sendNewsletter, email list
This commit is contained in:
2
infoZettelOrg/config.apiKey.yaml
Normal file
2
infoZettelOrg/config.apiKey.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
apiKey:
|
||||
createApiKey: "5fPsXG1JsAj"
|
||||
6
infoZettelOrg/config.arcorMail.yaml
Normal file
6
infoZettelOrg/config.arcorMail.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
smtp:
|
||||
serverAddress: "mail.arcor.de"
|
||||
serverPort: 465
|
||||
login: "cwsvjudo"
|
||||
password: "kodokan"
|
||||
senderEmailAddress: "cwsvjudo@arcor.de"
|
||||
6
infoZettelOrg/config.telekomMail.yaml
Normal file
6
infoZettelOrg/config.telekomMail.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
smtp:
|
||||
serverAddress: "securesmtp.t-online.de"
|
||||
serverPort: 465
|
||||
login: "judo.cwsv@t-online.de"
|
||||
password: "k0-d0-k4n"
|
||||
senderEmailAddress: "cwsvjudo@arcor.de"
|
||||
@@ -13,6 +13,13 @@
|
||||
"nick.weidensager@web.de"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "6",
|
||||
"loginName": "AlexanderDumler",
|
||||
"eMail": [
|
||||
"alled82@gmx.de"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "15",
|
||||
"loginName": "nSchmidl",
|
||||
@@ -53,7 +60,8 @@
|
||||
"id": "85",
|
||||
"loginName": "elternGerlach",
|
||||
"eMail": [
|
||||
"manja.bunzel@gmx.de"
|
||||
"manja.bunzel@gmx.de",
|
||||
"michael_gerlach@gmx.net"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -7,15 +7,17 @@ from email import utils
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
import pypandoc
|
||||
import yaml
|
||||
import argparse
|
||||
import certifi
|
||||
import os
|
||||
import requests
|
||||
import re
|
||||
import datetime
|
||||
import time
|
||||
import logging
|
||||
|
||||
# only for developing
|
||||
|
||||
# only for develop
|
||||
endDate = (datetime.datetime.now() +
|
||||
datetime.timedelta(days=7)).strftime("%Y-%m-%d")
|
||||
|
||||
@@ -36,10 +38,12 @@ class Email:
|
||||
|
||||
@staticmethod
|
||||
def loadFromMdFile(path):
|
||||
from yaml import safe_load
|
||||
|
||||
# read markdownfile as header and text
|
||||
mdHeader = None
|
||||
with open(argv.mdFilePath) as f:
|
||||
mdHeader = yaml.safe_load(get_yaml(f))
|
||||
mdHeader = safe_load(get_yaml(f))
|
||||
|
||||
title = mdHeader['title'] if checkHeader(
|
||||
mdHeader) else "cwsvJudo newsLetter"
|
||||
@@ -79,11 +83,11 @@ def checkHeader(header):
|
||||
"""
|
||||
retVal = True
|
||||
if not 'title' in header:
|
||||
print("Header has no 'title' attribute")
|
||||
logging.info("Header has no 'title' attribute!")
|
||||
retVal = False
|
||||
else:
|
||||
if header['title'] is False:
|
||||
print("Empty title!")
|
||||
logging.info("Empty title!")
|
||||
retVal = False
|
||||
return retVal
|
||||
|
||||
@@ -98,6 +102,15 @@ def getArguments():
|
||||
)
|
||||
argParser.add_argument(
|
||||
"-r", "--receiver", help="json file with the receiver")
|
||||
argParser.add_argument(
|
||||
"--dontSend",
|
||||
action="store_true"
|
||||
)
|
||||
argParser.add_argument(
|
||||
"-c", "--config",
|
||||
nargs="+", type=argparse.FileType("r"),
|
||||
help="yaml formatted config file(s)"
|
||||
)
|
||||
|
||||
return argParser.parse_args()
|
||||
|
||||
@@ -110,12 +123,11 @@ def loadFromJson(path):
|
||||
return jsonDict
|
||||
|
||||
|
||||
def loadFromYaml(path):
|
||||
yamlDict = None
|
||||
with open(path, "r") as yamlFile:
|
||||
yamlDict = yaml.safe_load(yamlFile)
|
||||
def loadFromYamlFile(yamlFile):
|
||||
from yaml import safe_load
|
||||
|
||||
return yamlDict
|
||||
with yamlFile as f:
|
||||
return safe_load(yamlFile)
|
||||
|
||||
|
||||
def createApiKey(allowKey, userId, rights, endDate):
|
||||
@@ -143,9 +155,23 @@ def createApiKey(allowKey, userId, rights, endDate):
|
||||
return jsonResponse['apiKey'] if 'apiKey' else None
|
||||
|
||||
|
||||
def randomSleep(min=60, max=600):
|
||||
from random import randint
|
||||
from time import sleep
|
||||
|
||||
sleepTime = randint(60, 600)
|
||||
logging.info(f"sleeping for {sleepTime} s")
|
||||
sleep(sleepTime)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
argv = getArguments()
|
||||
config = loadFromYaml("./config.yaml")
|
||||
|
||||
config = {}
|
||||
for yamlFile in argv.config:
|
||||
config |= loadFromYamlFile(yamlFile=yamlFile)
|
||||
|
||||
receivers = loadFromJson(argv.receiver)
|
||||
|
||||
emailTemplate = Email.loadFromMdFile(argv.mdFilePath)
|
||||
@@ -157,7 +183,7 @@ if __name__ == "__main__":
|
||||
apiKey = createApiKey(
|
||||
config['apiKey']['createApiKey'], user['id'], "login", endDate)
|
||||
if apiKey is None:
|
||||
print(f"Couldn't get apiKey")
|
||||
logging.info(f"Couldn't get apiKey for apiKey creation! Ok if no apiKey needs to be created.")
|
||||
continue
|
||||
|
||||
email = Email.loadFromMdFile(argv.mdFilePath) # emailTemplate
|
||||
@@ -205,9 +231,23 @@ if __name__ == "__main__":
|
||||
context.check_hostname = False
|
||||
context.verify_mode = ssl.CERT_NONE
|
||||
|
||||
|
||||
for message in messageQueue:
|
||||
# randomSleep(min=10, max=20)
|
||||
|
||||
with smtplib.SMTP_SSL(config['smtp']['serverAddress'], config['smtp']['serverPort'], context=context) as server:
|
||||
server.login(config['smtp']['login'], config['smtp']['password'])
|
||||
for message in messageQueue:
|
||||
print(f"sending to {message['To']}")
|
||||
server.sendmail(config['senderEmailAddress'],
|
||||
message["To"], message.as_string())
|
||||
if not argv.dontSend:
|
||||
logging.info(f"sending to {message['To']}")
|
||||
server.sendmail(
|
||||
from_addr=config['senderEmailAddress'],
|
||||
to_addrs=message["To"],
|
||||
msg=message.as_string()
|
||||
)
|
||||
# except smtplib.SMTPSenderRefused as exception:
|
||||
# if exception.smtp_code == 450:
|
||||
# logging.warning(f"Daily Quota exceded. Try again in 1h.")
|
||||
# time.sleep(60 * 60)
|
||||
# server.login(config['smtp']['login'], config['smtp']['password'])
|
||||
# logging.error(f"Unexpected SMTPSenderRefused exception: {exception} - {repr(exception)}")
|
||||
|
||||
Reference in New Issue
Block a user