Skip to content

Commit 145dccf

Browse files
committed
fixes and remove sendypy
1 parent 4603224 commit 145dccf

4 files changed

Lines changed: 45 additions & 56 deletions

File tree

weeklypedia/bake.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from dateutil.parser import parse as parse_date
1111
from ashes import TemplateNotFound
1212

13-
from mail import Mailinglist, KEY
13+
from mail import Mailinglist, sendy_send_campaign, KEY
1414
from fetch import get_latest_data_path
1515

1616
from common import (DATA_BASE_PATH,
@@ -80,9 +80,8 @@ def send(self, list_id, send_key):
8080
mailinglist.send_next_campaign()
8181
return 'Success: sent issue %s' % self.lang
8282

83-
def sendy_send(self, list_id, send_key):
84-
sendy = SendyMailinglist()
85-
sendy.create_and_send(self.subject, self.read_html(), self_read_text(), list_id)
83+
def sendy_send(self, list_id):
84+
sendy_send_campaign(self.subject, self.read_text(), self.read_html(), list_id)
8685
return 'Success: sent issue %s via sendy' % self.lang
8786

8887

weeklypedia/common.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,30 @@
1515
_CUR_PATH = dirname(os.path.abspath(__file__))
1616

1717
LANG_MAP = json.load(open(pjoin(_CUR_PATH, 'language_codes.json')))
18-
LOCAL_LANG_MAP = {'en': u'English',
19-
'de': u'Deutsch',
20-
'fr': u'Français',
21-
'ko': u'한국어',
22-
'et': u'Eesti',
23-
'sv': u'Svenska',
24-
'da': u'Dansk',
25-
'it': u'Italiano',
26-
'ca': u'Català',
27-
'es': u'Español',
28-
'fa': u'فارسی',
29-
'ur': u'اردو',
30-
'zh': u'中文',
31-
'kn': u'ಕನ್ನಡ',
32-
'lv': u'Latvian',
33-
'el': u'ελληνική',
34-
'te': u'తెలుగు',
35-
'oc': 'Occitan',
36-
'ru': 'Russian',
37-
'uk': 'Ukrainian'}
18+
LOCAL_LANG_MAP = {'en': u'English'}
19+
# 'de': u'Deutsch',
20+
# 'fr': u'Français',
21+
# 'ko': u'한국어',
22+
# 'et': u'Eesti',
23+
# 'sv': u'Svenska',
24+
# 'da': u'Dansk',
25+
# 'it': u'Italiano',
26+
# 'ca': u'Català',
27+
# 'es': u'Español',
28+
# 'fa': u'فارسی',
29+
# 'ur': u'اردو',
30+
# 'zh': u'中文',
31+
# 'kn': u'ಕನ್ನಡ',
32+
# 'lv': u'Latvian',
33+
# 'el': u'ελληνική',
34+
# 'te': u'తెలుగు',
35+
# 'oc': 'Occitan',
36+
# 'ru': 'Russian',
37+
# 'uk': 'Ukrainian'}
3838
SENDKEY = json.load(open(os.path.join(_CUR_PATH, 'secrets.json'))).get('key')
39-
SUPPORTED_LANGS = ['en', 'de', 'fr', 'ko', 'et', 'sv', 'da', 'it', 'ca', 'es',
40-
'fa', 'zh', 'ur', 'kn', 'lv', 'el', 'te', 'oc', 'ru', 'uk']
39+
SUPPORTED_LANGS = ['en']
40+
# 'de', 'fr', 'ko', 'et', 'sv', 'da', 'it', 'ca', 'es',
41+
# 'fa', 'zh', 'ur', 'kn', 'lv', 'el', 'te', 'oc', 'ru', 'uk']
4142
API_BASE_URL = 'http://weeklypedia.toolforge.org/fetch/'
4243

4344
ARCHIVE_BASE_PATH = pjoin(dirname(_CUR_PATH), 'static', 'archive')

weeklypedia/mail.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os
44
import json
55

6+
import requests
7+
68
import mailchimp
79

810
_CUR_PATH = os.path.dirname(os.path.abspath(__file__))
@@ -12,13 +14,29 @@
1214
KEY = secrets.get('mc')
1315
SENDY_KEY = secrets.get('sendy_key')
1416

15-
SENDY_URL 'https://mailer.hatnote.com/sendy'
17+
SENDY_URL = 'http://mailer.hatnote.com/s/'
1618
TEST_LIST_ID = "a5ecbc7404"
1719
DEFAULT_LIST = TEST_LIST_ID
1820

1921
# 'f811608f69'
2022

2123

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+
2240
class Mailinglist(object):
2341
def __init__(self, key):
2442
self.client = mailchimp.Mailchimp(key)
@@ -56,30 +74,6 @@ def get_next_campaign(self):
5674
return campaigns['data'][0]['id']
5775

5876

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-
8377
if __name__ == '__main__':
8478
mc = Mailinglist(KEY)
8579
import pdb; pdb.set_trace()

weeklypedia/publish.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ def send_issue(lang, mailer, is_dev=False):
3939
return result
4040

4141

42-
def send_send_issue(lang, is_dev=False):
43-
list_id = SENDY_LIST_ID_MAP[lang]
44-
cur_issue =
45-
46-
4742
def get_argparser():
4843
desc = 'Bake and send Weeklypedia issues. (Please fetch first)'
4944
prs = ArgumentParser(description=desc)

0 commit comments

Comments
 (0)