0

我正在使用 MailChimps inline-css 表单:http ://beaker.mailchimp.com/inline-css 。它在准备用于作为电子邮件发送的 html 文件方面做得很好。

我有一个 api 密钥。我不希望只为一个 API 调用运行他们的 PHP 应用程序。如果可以使用 curl 访问他们的 inlineCss API?如果是这样,语法是什么?

这是文档页面:http ://apidocs.mailchimp.com/api/1.2/inlinecss.func.php

另请参阅此要点的第 2096 行:https ://gist.github.com/740362

我的钥匙看起来像:f1b46???????????????????f2d5-us2

这是我想要实现的目标的开始:

curl post -d @input.html apiKey=xxxxxxxx "http://us1.api.mailchimp.com/1.2/"

谢谢

4

1 回答 1

1

这就是我为寻找类似解决方案的任何人所做的。欢迎评论,其他选项:

import os import re import urllib import mechanize import xml.sax.saxutils as saxutils from xml.sax.saxutils import unescape

try:  
  issueRoot = os.environ['newslettersroot'] + os.environ['currYear'] + '/' + os.environ['issueRoot'] + '/'
except KeyError: 
   print "Please run init.bat"
   sys.exit(1)

srcEmailFilename = 'email.html'
dstEmailFilename = 'email_inline_css.html'


# retrieve <body> section only
html = open(issueRoot + srcEmailFilename, 'rb').read()
html = re.findall("(?si)<body.*?</body>", html)[0]


# use mailchimp inlineCss site to inject class rules into html tags
response = mechanize.urlopen("http://beaker.mailchimp.com/inline-css")
# retrieve form
form = mechanize.ParseResponse(response, backwards_compat=False)[0]

form["html"] = html
# form["strip"] = "checked"

# submit form and retrieve result
html = mechanize.urlopen(form.click()).read()


match = re.search('<textarea name="text" cols="100" rows="12">(.*?)</textarea>', html, re.DOTALL | re.IGNORECASE | re.MULTILINE)

if not match:
    print html
    exit("Expected to find output from mailchimp.")

# clean up output
html = match.group(1)
html = saxutils.unescape(html)
html = urllib.unquote_plus(html)
html = unescape(html, {"&apos;": "'", "&quot;": '"'})
html = html.replace('&amp;', '&').replace('%2F', '/').replace('%3A', ':')


# @sed -r 's/ class="[a-zA-Z0-9-]+"//g' %newslettersroot%%currYear%\%issueRoot%\email_inlinedcss.html > %newslettersroot%%currYear%\%issueRoot%\email_removedstyle.html

#replace class tags
html = re.sub(r'(?sim)\s*class="[a-zA-Z0-9-]+"', "", html)

fh = open(issueRoot + dstEmailFilename, 'wb')
fh.write(html)
fh.close()
于 2012-07-09T20:41:57.957 回答