Skip to content

Instantly share code, notes, and snippets.

@naveed125
Last active May 27, 2018 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naveed125/bd91c6ffd80b73d862114fb2e53c0e2b to your computer and use it in GitHub Desktop.
Save naveed125/bd91c6ffd80b73d862114fb2e53c0e2b to your computer and use it in GitHub Desktop.
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