Skip to content
Snippets Groups Projects
Commit 46e8cb35 authored by Thomas Bock's avatar Thomas Bock :speech_balloon:
Browse files

pre/post reminder

parent 93da8234
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,8 @@ from datetime import datetime, timedelta ...@@ -7,7 +7,8 @@ from datetime import datetime, timedelta
db_url = "http://a73434.berlin.ptb.de:5984/vl_db/_design/share/_view/pla_date" db_url = "http://a73434.berlin.ptb.de:5984/vl_db/_design/share/_view/pla_date"
relay_url = "http://a73434.berlin.ptb.de:55555" relay_url = "http://a73434.berlin.ptb.de:55555"
to_mail = "thomas.bock@ptb.de" to_mail = "thomas.bock@ptb.de"
N = 20 post_days = 20
pre_days = 90
opening= { opening= {
'male': { 'male': {
...@@ -23,26 +24,49 @@ opening= { ...@@ -23,26 +24,49 @@ opening= {
"de": "Sehr geehrte Damen und Herren," "de": "Sehr geehrte Damen und Herren,"
} }
} }
body = { body_post = {
'en': "your reservation of the time slot {schedule_date} for calibration is about to expire.\nWould you like to order this calibration?", 'en': "your reservation of the time slot {schedule_date} for calibration is about to expire.\nWould you like to order this calibration?",
'de' : "die Reservierung Ihres Kalibriertermins zum {schedule_date} läuft in Kürze ab.\nMöchten Sie diese Kalibrierung in Auftrag geben?" 'de' : "die Reservierung Ihres Kalibriertermins zum {schedule_date} läuft in Kürze ab.\nMöchten Sie diese Kalibrierung in Auftrag geben?"
}
body_pre = {
'en': "Anstehende Kalibrierung am {schedule_date}",
'de' : "Anstehende Kalibrierung am {schedule_date} "
} }
closing = { closing = {
'en': "Best regards,", 'en': "Best regards,",
'de' : "Mit freundlichen Grüßen" 'de' : "Mit freundlichen Grüßen"
} }
subject = {
'en': "Angebot vom {ref_date} (zum Weiterleiten an {email})", subject_pre = {
'de' : "Offer from {ref_date} (zum Weiterleiten an {email})" 'en': "Angebot zur Kalibrierung am {date} (zum Weiterleiten an {email})",
'de' : "Offer for calibration at {date} (zum Weiterleiten an {email})"
}
subject_post = {
'en': "Ihre Kalibrierung am {date} (zum Weiterleiten an {email})",
'de' : "Your calibration at {date} (zum Weiterleiten an {email})"
} }
date_post_days = datetime.now() - timedelta(days=post_days)
ref_post_date = str(date_post_days).split(" ")[0]
date_pre_days = datetime.now() + timedelta(days=pre_days)
ref_pre_date = str(date_pre_days).split(" ")[0]
date_N_days = datetime.now() - timedelta(days=N) req_post = requests.get("{url}?key=\"{key}\"".format(url=db_url, key=ref_post_date))
ref_date = str(date_N_days).split(" ")[0] req_pre = requests.get("{url}?key=\"{key}\"".format(url=db_url, key=ref_pre_date))
req = requests.get("{url}?key=\"{key}\"".format(url=db_url, key=ref_date)) plannings = []
plannings = req.json() for p in req_post.json()["rows"]:
p["match"] = "post"
plannings.append(p)
for pla in plannings["rows"]: for p in req_pre.json()["rows"]:
p["match"] = "pre"
plannings.append(p)
for pla in plannings:
schedule_date = pla.get("value",{}).get("ScheduleDate") schedule_date = pla.get("value",{}).get("ScheduleDate")
customer = pla.get("value",{}).get("Customer", {}) customer = pla.get("value",{}).get("Customer", {})
contact = customer.get("Contact") contact = customer.get("Contact")
...@@ -51,9 +75,15 @@ for pla in plannings["rows"]: ...@@ -51,9 +75,15 @@ for pla in plannings["rows"]:
name = contact.get("Name") name = contact.get("Name")
gender = contact.get("Gender", "none") gender = contact.get("Gender", "none")
email = contact.get("Email") email = contact.get("Email")
mail_subject = subject[lang].format(ref_date=ref_date, email=email)
mail_opening = opening[gender][lang].format(name=name) mail_opening = opening[gender][lang].format(name=name)
mail_body = body[lang].format(schedule_date=schedule_date)
if pla.get("match") == "pre":
mail_subject = subject_pre[lang].format(date=ref_pre_date, email=email)
mail_body = body_pre[lang].format(schedule_date=schedule_date)
if pla.get("match") == "post":
mail_subject = subject_post[lang].format(date=ref_post_date, email=email)
mail_body = body_post[lang].format(schedule_date=schedule_date)
mail_closing = closing[lang] mail_closing = closing[lang]
mail = "{}\n\n{}\n\n{}".format(mail_opening, mail_body,mail_closing) mail = "{}\n\n{}\n\n{}".format(mail_opening, mail_body,mail_closing)
task = {"Action":"EMAIL", task = {"Action":"EMAIL",
...@@ -62,4 +92,5 @@ for pla in plannings["rows"]: ...@@ -62,4 +92,5 @@ for pla in plannings["rows"]:
"From": "<reminder@ptb.de>", "From": "<reminder@ptb.de>",
"To": to_mail, "To": to_mail,
"Text": mail} "Text": mail}
req = requests.post(relay_url, data=json.dumps(task)) print(task)
\ No newline at end of file #req = requests.post(relay_url, data=json.dumps(task))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment