commit 6bf38073d6c24777da545248dfe9e89d7d384eda
parent 9a361b6702a14efb7adf1996f505943363a7fe67
Author: David Eisinger <[email protected]>
Date: Fri, 23 Feb 2024 23:06:31 -0500
Add newsletter script
Diffstat:
1 file changed, 49 insertions(+), 0 deletions(-)
diff --git a/bin/newsletter b/bin/newsletter
@@ -0,0 +1,49 @@
+#!/usr/bin/env ruby
+
+require "httparty"
+require "nokogiri"
+require "open-uri"
+
+feed = Nokogiri::XML(
+ URI.open("https://davideisinger.com/index.xml")
+)
+
+post = feed.search("rss channel item").first
+title = post.search("title").text
+url = post.search("link").text
+
+body = %(<h1>#{title}</h1>
+<p>
+ By David Eisinger ·
+ <a href="#{url}">View original post</a>
+</p>
+#{post.search("description").text}
+)
+ .gsub("{", "{")
+ .gsub("}", "}")
+ .gsub(/width="(\d+)"/) do
+ %(width="#{$1.to_i/2}")
+ end
+ .gsub(/height="(\d+)"/) do
+ %(height="#{$1.to_i/2}")
+ end
+ .gsub(/<audio controls src="([^"]+)"><\/audio>/) do
+ filename = $1.split("/").last
+ %(<a href="#{$1}">#{filename}</a>)
+ end
+
+p HTTParty.post(
+ "https://dispatch.davideisinger.com/api/campaigns",
+ basic_auth: {
+ username: ENV["USERNAME"],
+ password: ENV["PASSWORD"]
+ },
+ headers: { 'Content-Type' => 'application/json' },
+ body: {
+ name: title,
+ subject: title,
+ body: body,
+ lists: [1]
+ }.to_json,
+ debug_output: $stdout
+)