Skip to content

Commit

Permalink
Merge pull request #13 from akito19/fix-sample-script
Browse files Browse the repository at this point in the history
Fix Python script for example
  • Loading branch information
akito19 authored Jul 16, 2021
2 parents a3e73f9 + 367398b commit bcff187
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
39 changes: 10 additions & 29 deletions src/examples/mailchimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# FIXME: Change this email address
FROM_EMAIL = "[email protected]"

def start(audience_name, reason, template_name, campaign_ja, campaign_en, job_id, db, table, email):
def start(audience_name, reason, template_name, campaign_title, job_id, db, table, email):
mailchimp = Mailchimp.Client()
mailchimp.set_config({
"api_key": os.environ["MAILCHIMP_APIKEY"],
Expand All @@ -26,7 +26,7 @@ def start(audience_name, reason, template_name, campaign_ja, campaign_en, job_id
template_id = upload_template(mailchimp, template_name)

# Campaign
create_campaign(mailchimp, template_id, campaign_ja, campaign_en)
create_campaign(mailchimp, template_id, campaign_title)

def extract_job_result(job_id, db, table, target_email):
import tdclient
Expand Down Expand Up @@ -179,32 +179,17 @@ def upload_template(mailchimp, template_name):
sys.exit(1)

# https://mailchimp.com/developer/marketing/api/campaigns/add-campaign/
def create_campaign(mailchimp, template_id, campaign_ja, campaign_en):
def create_campaign(mailchimp, template_id, campaign_title):
if not template_id:
print('Error: Failed to get the template id')
sys.exit(1)

content_ja = {
content = {
"type": "regular",
"settings": {
"subject_line": "subject line",
"preview_text": "preview text",
"title": campaign_ja,
"from_name": "{your_name}",
"reply_to": FROM_EMAIL,
"use_conversation": False,
"to_name": "email_address",
"template_id": template_id,
"fb_comments": False
}
}

content_en = {
"type": "regular",
"settings": {
"subject_line": "subject line",
"preview_text": "preview text",
"title": campaign_en,
"title": campaign_title,
"from_name": "{your_name}",
"reply_to": FROM_EMAIL,
"use_conversation": False,
Expand All @@ -215,10 +200,8 @@ def create_campaign(mailchimp, template_id, campaign_ja, campaign_en):
}

try:
print("Creating a campaing in Japanese version...")
mailchimp.campaigns.create(content_ja)
print("Creating a campaing in English version...")
mailchimp.campaigns.create(content_en)
print("Creating a campaing...")
mailchimp.campaigns.create(content)
print("Campaign created")
except ApiClientError as error:
print("Error: {}".format(error.text))
Expand All @@ -230,20 +213,18 @@ def create_campaign(mailchimp, template_id, campaign_ja, campaign_en):
parser.add_argument("audience_name", help="Audience name", type=str)
parser.add_argument("reason", help="Reason why customers get this notification", type=str)
parser.add_argument("template_name", help="Template name", type=str)
parser.add_argument("campaign_ja", help="Campaign name (Japanese)", type=str)
parser.add_argument("campaign_en", help="Campaign name (English)", type=str)
parser.add_argument("campaign_title", help="Campaign name", type=str)
parser.add_argument("job_id", help="Job ID", type=int)
parser.add_argument("db", help="Database name for rejected users", type=int)
parser.add_argument("table", help="Table name for rejected users", type=int)
parser.add_argument("email", help="Email address", type=str)
audience_name = args.audience_name
reason = args.reason
template_name = args.template_name
campaign_ja = args.campaign_ja
campaign_en = args.campaign_en
campaign_title = args.campaign_title
job_id = args.job_id
db = args.db
table = args.table
email = args.email

start(audience_name, reason, template_name, campaign_ja, campaign_en, job_id, email)
start(audience_name, reason, template_name, campaign_title, job_id, email)
3 changes: 1 addition & 2 deletions src/examples/notification.dig
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ _export:
audience_name: 'Audience name'
reason: 'Write the reason why customers get this notification.'
template_name: 'Template name (Email content)'
campaign_ja: 'campaign name 1'
campaign_en: 'campaign name 2'
campaign_title: 'campaign name 1'
# Properties for Treasure Data
job_id: ${td.last_job_id}
db: ${td.database} # This value will be used for rejected users.
Expand Down

0 comments on commit bcff187

Please sign in to comment.