|
3 | 3 | import os |
4 | 4 | import json |
5 | 5 |
|
| 6 | +import requests |
| 7 | + |
6 | 8 | import mailchimp |
7 | 9 |
|
8 | 10 | _CUR_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
12 | 14 | KEY = secrets.get('mc') |
13 | 15 | SENDY_KEY = secrets.get('sendy_key') |
14 | 16 |
|
15 | | -SENDY_URL 'https://mailer.hatnote.com/sendy' |
| 17 | +SENDY_URL = 'http://mailer.hatnote.com/s/' |
16 | 18 | TEST_LIST_ID = "a5ecbc7404" |
17 | 19 | DEFAULT_LIST = TEST_LIST_ID |
18 | 20 |
|
19 | 21 | # 'f811608f69' |
20 | 22 |
|
21 | 23 |
|
| 24 | +def sendy_send_campaign(subject, text_content, html_content, list_id): |
| 25 | + url = SENDY_URL + 'api/campaigns/create.php' |
| 26 | + data = {'from_name': 'Weeklypedia Digest', |
| 27 | + 'from_email': 'weeklypedia@hatnote.com', |
| 28 | + 'reply_to': 'weeklypedia@hatnote.com', |
| 29 | + 'title': subject, |
| 30 | + 'subject': subject, |
| 31 | + 'plain_text': text_content, |
| 32 | + 'html_text': html_content, |
| 33 | + 'list_ids': list_id, |
| 34 | + 'send_campaign': 1, |
| 35 | + 'api_key': SENDY_KEY} |
| 36 | + resp = requests.post(url, data=data) |
| 37 | + return resp |
| 38 | + |
| 39 | + |
22 | 40 | class Mailinglist(object): |
23 | 41 | def __init__(self, key): |
24 | 42 | self.client = mailchimp.Mailchimp(key) |
@@ -56,30 +74,6 @@ def get_next_campaign(self): |
56 | 74 | return campaigns['data'][0]['id'] |
57 | 75 |
|
58 | 76 |
|
59 | | -class SendyMailinglist(object): |
60 | | - def __init__(self): |
61 | | - self.key = key |
62 | | - self.client = SendyAPI(host=SENDY_URL, |
63 | | - api_key=SENDY_KEY) |
64 | | - |
65 | | - def create_and_send(self, |
66 | | - subject, |
67 | | - html_content, |
68 | | - text_content, |
69 | | - list_id): |
70 | | - resp = client.create_campaign( |
71 | | - from_name='Weeklypedia Digest', |
72 | | - from_email='weeklypedia@hatnote.com', |
73 | | - reply_to='weeklypedia@hatnote.com', |
74 | | - title=subject, |
75 | | - subject=subject, |
76 | | - plain_text=text_content, |
77 | | - html_text=html_content, |
78 | | - list_ids=list_id, |
79 | | - send_campaign=1, # if 0, then it will be saved as a draft. How do you send a draft campaign? |
80 | | - ) |
81 | | - print resp |
82 | | - |
83 | 77 | if __name__ == '__main__': |
84 | 78 | mc = Mailinglist(KEY) |
85 | 79 | import pdb; pdb.set_trace() |
0 commit comments