Skip to content

Instantly share code, notes, and snippets.



Last active Jul 12, 2018
What would you like to do?
A funky little script to download Drip broadcast messages and create Jekyll-ready Markdown files. See for updated version.
#!/usr/bin/env ruby
# A little Ruby script to download your Drip broadcast messages to Jekyll-ready
# Markdown files. These could be used as posts or, better yet, as a collection.
# Inspired by Jonathan Stark's Drain
# Copyright Ben Lopatin, 2018
# Shared with an MIT license:
# Since this is a standalone script, installing the dependencies is your responsibility
# - drip-ruby
# - slugify
# - reverse_markdown
# The _drain.yml file should include 3 key, value pairs:
# account_id: the ID of your Drip account
# api_key: your API key for accessing the Drip API
# directory: the directory where you'll include all of your new files
# TODO: make broadcast status from env/arg
# TODO: filter braodcasts based on groups
require 'date'
require 'yaml'
require 'drip'
require 'slugify'
require 'reverse_markdown'
if File.exist?("_drain.yml")
CONF = YAML.load(, "_drain.yml"), File::RDONLY).read)
abort("Cannot find your _drain.yml configuration file")
target = File.join(File.dirname(__FILE__), CONF["directory"])
overwrite = false
options = {
status: "sent"
client = do |c|
c.api_key = CONF["api_key"]
c.account_id = CONF["account_id"]
response = client.broadcasts(options)
if response.success?
for broadcast in response.body["broadcasts"]
slug = broadcast["subject"].slugify
filename = File.join(target, slug + '.md')
if overwrite or !File.file?(filename)
frontmatter = {
"title" => broadcast["subject"],
"layout" => "newsletter",
"published" => true,
"date" => broadcast["send_at"]
body = ReverseMarkdown.convert broadcast["html_body"].split("{%")[0]
content = [frontmatter.to_yaml, body].join("\n"), 'w') { |file| file.write(content) }
abort("API failure!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment