Skip to content

Instantly share code, notes, and snippets.

@naveed125

naveed125/DataDriven.py

Last active May 27, 2018
Embed
What would you like to do?
Data Driven Programming
from User import User
from EmailService import EmailService
#
# rules data
#
rule_set = [
{
"country": ["fr"],
"subject": "Bonjour et bienvenue sur notre site",
"content": "Bonjour et Bienvenue sur notre tout nouveau site. Contactez l'équipe de support si vous avez des..."
},
{
"country": ["us", "ca"],
"subject": "Welcome to our site",
"content": "Hello and Welcome to our brand new site. Contact support team if you have any questions."
},
{
"min_age": 18,
"subject": "Important reminder",
"content": "Important: Please note that user under the age of 18 must provide a signed waiver from a parent ..."
},
{
"payment_status": "Unverified",
"subject": "Reminder about your payment status",
"content": "Please don't forget to update your payment information on our site"
}
]
#
# main function
#
def main():
#
# Fetch the current user
#
user = User()
user.load_from_session()
#
# Process the config data and fire actions
#
for rule in rule_set:
# Process country rule
if "country" in rule and user.country in rule["country"]:
EmailService.send(user.email, rule["subject"], rule["content"])
# Process minimum age rule
if "min_age" in rule and user.age < rule["min_age"]:
EmailService.send(user.email, rule["subject"], rule["content"])
# Process payment status rule
if "payment_status" in rule and user.payment_status == rule["payment_status"]:
EmailService.send(user.email, rule["subject"], rule["content"])
#
# run main
#
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment