send confirmation mail, write to csv
This commit is contained in:
parent
224ffbe65c
commit
0398c19aa5
@ -10,15 +10,25 @@
|
|||||||
#
|
#
|
||||||
import sys
|
import sys
|
||||||
import imaplib
|
import imaplib
|
||||||
import getpass
|
import os
|
||||||
|
import sys
|
||||||
import email
|
import email
|
||||||
import email.header
|
import email.header
|
||||||
from IPython import embed
|
from IPython import embed
|
||||||
|
import smtplib
|
||||||
|
from email.message import EmailMessage
|
||||||
import re
|
import re
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
|
|
||||||
EMAIL_ACCOUNT = "bzigr02"
|
EMAIL_ACCOUNT = "bzigr02"
|
||||||
EMAIL_FOLDER = "INBOX"
|
EMAIL_FOLDER = "INBOX"
|
||||||
|
EMAIL_ADDRESS = 'etho2020registration@biologie.uni-tuebingen.de'
|
||||||
|
EMAIL_REPLY = 'etho2020@biologie.uni-tuebingen.de'
|
||||||
|
SMTP_SERVER = 'smtpserv.uni-tuebingen.de'
|
||||||
|
IMAP_SERVER = 'mailserv.uni-tuebingen.de'
|
||||||
|
EMAIL_PSWD = "r.8-*0Fc"
|
||||||
|
|
||||||
|
PARTICIPANTS_FOLDER = 'participants'
|
||||||
|
|
||||||
reg_fees = {'early': {"proMember": 95, "proNonMember":115, "studentMember": 55, "studentNonMember": 65},
|
reg_fees = {'early': {"proMember": 95, "proNonMember":115, "studentMember": 55, "studentNonMember": 65},
|
||||||
'late': {"proMember": 115, "proNonMember":135, "studentMember": 65, "studentNonMember": 75}}
|
'late': {"proMember": 115, "proNonMember":135, "studentMember": 65, "studentNonMember": 75}}
|
||||||
@ -138,16 +148,38 @@ class Participation(object):
|
|||||||
def valid(self):
|
def valid(self):
|
||||||
return len(self._conflicts) == 0
|
return len(self._conflicts) == 0
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return "%s %s" % (self._first_name, self._last_name)
|
||||||
|
|
||||||
|
def save_to_csv(self, filename=None):
|
||||||
|
if not os.path.exists(PARTICIPANTS_FOLDER):
|
||||||
|
os.mkdir(PARTICIPANTS_FOLDER)
|
||||||
|
if not filename:
|
||||||
|
filename = os.path.join(PARTICIPANTS_FOLDER, "".join(p.name.split())) + ".csv"
|
||||||
|
header = ["LastName", "FirstName", "eMail", "Phone", "Institute", "Street", "City",
|
||||||
|
"RegDate", "CareerStage", "Fee", "FarewellEvent", "GwinnerAward", "LabTour",
|
||||||
|
"FoodVegetarian", "FoodVegan", "FoodGlutenFree", "FoodNoPref"]
|
||||||
|
values = [self._first_name, self._last_name, self._email, self._phone, self._institution,
|
||||||
|
self._address_street, "%s %s" % (self._address_zip, self._address_city),
|
||||||
|
self.registration_date.isoformat(), self._role, str(self.fee), str(self.farewell_event),
|
||||||
|
str(self.gwinner_award), str(self.labtour), str(self._food_vegi), str(self._food_vegan),
|
||||||
|
str(self._food_gluten), str(self._food_normal)]
|
||||||
|
with open(filename, "w") as f:
|
||||||
|
f.write("; ".join(header))
|
||||||
|
f.write("\n")
|
||||||
|
f.write("; ".join(values))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
str = ""
|
str = ""
|
||||||
str += "Name: %s %s\n" % (self._first_name, self._last_name)
|
str += "Name: %s %s\n" % (self._first_name, self._last_name)
|
||||||
str += "Institution: %s\n" % self._institution
|
str += "Institution: %s\n" % self._institution
|
||||||
str += "Phone: %s\n" % self._phone
|
str += "Phone: %s\n" % self._phone
|
||||||
str += "e-Mail: %s\n" % self._email
|
str += "e-Mail: %s\n" % self._email
|
||||||
str += "%s %s\n" % ("senior" if "pro" in self._role else "student",
|
str += "Career stage: %s %s\n" % ("senior" if "pro" in self._role else "student",
|
||||||
"non-member" if "NonMember" in self._role else "member")
|
"non-member" if "NonMember" in self._role else "member of Ethological Soc.")
|
||||||
str += "Farewell event: %s\n" % "Yes" if self.farewell_event else "No"
|
str += "Farewell event: %s\n" % "Yes" if self.farewell_event else "No"
|
||||||
str += "Fee: %f Eur\n" % self.fee
|
str += "Fee: %3.2f EUR\n" % self.fee
|
||||||
str += "Lab tour: %s\n" % ( "No" if len(self.labtour) == 0 else "Yes, " + ", ".join(self.labtour))
|
str += "Lab tour: %s\n" % ( "No" if len(self.labtour) == 0 else "Yes, " + ", ".join(self.labtour))
|
||||||
str += "Gwinner award: %s\n" % "Yes" if self.gwinner_award else "No"
|
str += "Gwinner award: %s\n" % "Yes" if self.gwinner_award else "No"
|
||||||
str += "Food preferences: %s, %s, %s, %s\n" % ("no prefs" if self._food_normal else "",
|
str += "Food preferences: %s, %s, %s, %s\n" % ("no prefs" if self._food_normal else "",
|
||||||
@ -215,31 +247,50 @@ def process_registrations(M):
|
|||||||
return participations
|
return participations
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def send_confirmation(p=None):
|
||||||
M = imaplib.IMAP4_SSL('mailserv.uni-tuebingen.de')
|
if p is not None:
|
||||||
passwd = "r.8-*0Fc"
|
assert(isinstance(p, Participation))
|
||||||
|
content = "Dear %s," % (p.name if p else "participant")
|
||||||
|
with open("response.txt") as fp:
|
||||||
|
content += fp.read()
|
||||||
|
content += "\n"
|
||||||
|
content += str(p) if p else ""
|
||||||
|
msg = EmailMessage()
|
||||||
|
msg.set_content(content)
|
||||||
|
msg['Subject'] = 'Etho 2020 registration confirmation'
|
||||||
|
msg['From'] = EMAIL_ADDRESS
|
||||||
|
msg['To'] = 'jan.grewe@uni-tuebingen.de'
|
||||||
|
msg['Reply-to'] = EMAIL_REPLY
|
||||||
|
|
||||||
|
s = smtplib.SMTP(SMTP_SERVER)
|
||||||
|
s.starttls()
|
||||||
|
s.login(EMAIL_ACCOUNT, EMAIL_PSWD)
|
||||||
|
s.send_message(msg)
|
||||||
|
|
||||||
|
|
||||||
|
s.quit()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
M = imaplib.IMAP4_SSL(IMAP_SERVER)
|
||||||
try:
|
try:
|
||||||
rv, data = M.login(EMAIL_ACCOUNT, passwd)
|
rv, data = M.login(EMAIL_ACCOUNT, EMAIL_PSWD)
|
||||||
except imaplib.IMAP4.error:
|
except imaplib.IMAP4.error:
|
||||||
print ("LOGIN FAILED!!! ")
|
print ("LOGIN FAILED!!! ")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
# rv, mailboxes = M.list()
|
||||||
#rv, mailboxes = M.list()
|
# if rv == 'OK':
|
||||||
#if rv == 'OK':
|
|
||||||
# print("Mailboxes:")
|
# print("Mailboxes:")
|
||||||
# print(mailboxes)
|
# print(mailboxes)
|
||||||
|
|
||||||
rv, data = M.select(EMAIL_FOLDER)
|
rv, data = M.select(EMAIL_FOLDER)
|
||||||
if rv == 'OK':
|
if rv != 'OK':
|
||||||
print("Processing mailbox %s\n"%EMAIL_FOLDER)
|
|
||||||
# process_mailbox(M)
|
|
||||||
else:
|
|
||||||
print("ERROR: Unable to open mailbox folder ", rv)
|
print("ERROR: Unable to open mailbox folder ", rv)
|
||||||
|
|
||||||
new_participations = process_registrations(M)
|
new_participations = process_registrations(M)
|
||||||
for p in new_participations:
|
for p in new_participations:
|
||||||
print(p)
|
print(p.name)
|
||||||
|
p.save_to_csv()
|
||||||
|
send_confirmation(p)
|
||||||
M.close()
|
M.close()
|
||||||
M.logout()
|
M.logout()
|
||||||
|
|
||||||
|
20
response.txt
Normal file
20
response.txt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
thank you for registering for the 15th annual meeting of the
|
||||||
|
Ethological Society held in Tuebingen 18 - 21 February 2020.
|
||||||
|
|
||||||
|
By registering you agree to pay the respective conference fee (plus
|
||||||
|
costs of the farewell event, if applicable). Payments must be received
|
||||||
|
by 15 Jan 2020. Wire transfer to:
|
||||||
|
|
||||||
|
Account holder: Universität Tübingen
|
||||||
|
Bank: Kreissparkasse Tübingen
|
||||||
|
IBAN: DE13 6415 0020 0000 0130 04,
|
||||||
|
BIC: SOLADES1TUB
|
||||||
|
Purpose of use: etho2020, Fonds 3190, PSP 3132012401
|
||||||
|
|
||||||
|
For more information visit the conference website www.etho2020.de
|
||||||
|
|
||||||
|
Abstract submission is handled via this site: https://abstracts.g-node.org/conference/etho2020
|
||||||
|
|
||||||
|
Please contact us if the information below is incorrect.
|
||||||
|
|
||||||
|
----8<------------------------------8<------------------
|
Loading…
Reference in New Issue
Block a user