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"
|
"nick.weidensager@web.de"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "6",
|
||||||
|
"loginName": "AlexanderDumler",
|
||||||
|
"eMail": [
|
||||||
|
"alled82@gmx.de"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "15",
|
"id": "15",
|
||||||
"loginName": "nSchmidl",
|
"loginName": "nSchmidl",
|
||||||
@@ -53,7 +60,8 @@
|
|||||||
"id": "85",
|
"id": "85",
|
||||||
"loginName": "elternGerlach",
|
"loginName": "elternGerlach",
|
||||||
"eMail": [
|
"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.text import MIMEText
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
import pypandoc
|
import pypandoc
|
||||||
import yaml
|
|
||||||
import argparse
|
import argparse
|
||||||
import certifi
|
import certifi
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
import re
|
import re
|
||||||
import datetime
|
import datetime
|
||||||
|
import time
|
||||||
|
import logging
|
||||||
|
|
||||||
# only for developing
|
|
||||||
|
# only for develop
|
||||||
endDate = (datetime.datetime.now() +
|
endDate = (datetime.datetime.now() +
|
||||||
datetime.timedelta(days=7)).strftime("%Y-%m-%d")
|
datetime.timedelta(days=7)).strftime("%Y-%m-%d")
|
||||||
|
|
||||||
@@ -36,10 +38,12 @@ class Email:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def loadFromMdFile(path):
|
def loadFromMdFile(path):
|
||||||
|
from yaml import safe_load
|
||||||
|
|
||||||
# read markdownfile as header and text
|
# read markdownfile as header and text
|
||||||
mdHeader = None
|
mdHeader = None
|
||||||
with open(argv.mdFilePath) as f:
|
with open(argv.mdFilePath) as f:
|
||||||
mdHeader = yaml.safe_load(get_yaml(f))
|
mdHeader = safe_load(get_yaml(f))
|
||||||
|
|
||||||
title = mdHeader['title'] if checkHeader(
|
title = mdHeader['title'] if checkHeader(
|
||||||
mdHeader) else "cwsvJudo newsLetter"
|
mdHeader) else "cwsvJudo newsLetter"
|
||||||
@@ -79,11 +83,11 @@ def checkHeader(header):
|
|||||||
"""
|
"""
|
||||||
retVal = True
|
retVal = True
|
||||||
if not 'title' in header:
|
if not 'title' in header:
|
||||||
print("Header has no 'title' attribute")
|
logging.info("Header has no 'title' attribute!")
|
||||||
retVal = False
|
retVal = False
|
||||||
else:
|
else:
|
||||||
if header['title'] is False:
|
if header['title'] is False:
|
||||||
print("Empty title!")
|
logging.info("Empty title!")
|
||||||
retVal = False
|
retVal = False
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
@@ -98,6 +102,15 @@ def getArguments():
|
|||||||
)
|
)
|
||||||
argParser.add_argument(
|
argParser.add_argument(
|
||||||
"-r", "--receiver", help="json file with the receiver")
|
"-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()
|
return argParser.parse_args()
|
||||||
|
|
||||||
@@ -110,12 +123,11 @@ def loadFromJson(path):
|
|||||||
return jsonDict
|
return jsonDict
|
||||||
|
|
||||||
|
|
||||||
def loadFromYaml(path):
|
def loadFromYamlFile(yamlFile):
|
||||||
yamlDict = None
|
from yaml import safe_load
|
||||||
with open(path, "r") as yamlFile:
|
|
||||||
yamlDict = yaml.safe_load(yamlFile)
|
|
||||||
|
|
||||||
return yamlDict
|
with yamlFile as f:
|
||||||
|
return safe_load(yamlFile)
|
||||||
|
|
||||||
|
|
||||||
def createApiKey(allowKey, userId, rights, endDate):
|
def createApiKey(allowKey, userId, rights, endDate):
|
||||||
@@ -143,9 +155,23 @@ def createApiKey(allowKey, userId, rights, endDate):
|
|||||||
return jsonResponse['apiKey'] if 'apiKey' else None
|
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__":
|
if __name__ == "__main__":
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
argv = getArguments()
|
argv = getArguments()
|
||||||
config = loadFromYaml("./config.yaml")
|
|
||||||
|
config = {}
|
||||||
|
for yamlFile in argv.config:
|
||||||
|
config |= loadFromYamlFile(yamlFile=yamlFile)
|
||||||
|
|
||||||
receivers = loadFromJson(argv.receiver)
|
receivers = loadFromJson(argv.receiver)
|
||||||
|
|
||||||
emailTemplate = Email.loadFromMdFile(argv.mdFilePath)
|
emailTemplate = Email.loadFromMdFile(argv.mdFilePath)
|
||||||
@@ -157,7 +183,7 @@ if __name__ == "__main__":
|
|||||||
apiKey = createApiKey(
|
apiKey = createApiKey(
|
||||||
config['apiKey']['createApiKey'], user['id'], "login", endDate)
|
config['apiKey']['createApiKey'], user['id'], "login", endDate)
|
||||||
if apiKey is None:
|
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
|
continue
|
||||||
|
|
||||||
email = Email.loadFromMdFile(argv.mdFilePath) # emailTemplate
|
email = Email.loadFromMdFile(argv.mdFilePath) # emailTemplate
|
||||||
@@ -205,9 +231,23 @@ if __name__ == "__main__":
|
|||||||
context.check_hostname = False
|
context.check_hostname = False
|
||||||
context.verify_mode = ssl.CERT_NONE
|
context.verify_mode = ssl.CERT_NONE
|
||||||
|
|
||||||
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:
|
||||||
for message in messageQueue:
|
# randomSleep(min=10, max=20)
|
||||||
print(f"sending to {message['To']}")
|
|
||||||
server.sendmail(config['senderEmailAddress'],
|
with smtplib.SMTP_SSL(config['smtp']['serverAddress'], config['smtp']['serverPort'], context=context) as server:
|
||||||
message["To"], message.as_string())
|
server.login(config['smtp']['login'], config['smtp']['password'])
|
||||||
|
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