I'm using Zapier to run a search on Twitter, create a daily digest of results (Zapier Digest), and send the digest to a mailing list (Mailgun). I seek to format the Tweets similar to Twitter's own emails where the tweet isn't text but HTML where any user mention (@name, corresponding URL is https://twitter.com/[NAME]) and URL in the tweet are actual links. (I don't want the conversion for any hashtags.)
This search, extract, and replace (with added HTML) isn't that hard. But it's too much for Zapier's simple Formatter text functions. So I turned to the Zapier Code action, thinking I could borrow code as I'm not a hardcore coder.
I found Python code as below (and others at that site). After a couple hours of testing I've given up on being able to successfully adapt it for use in Zapier Code. Zapier has limitations on how it uses Python. Their documentation on it is primitive.
Could someone here familiar with Zapier help me with converting that (or similar) code so I could run it on Zapier Python or Javascript? I truly would appreciate it.
Thank you, Marc
https://coderwall.com/p/wdtkhw/convert-links-username-mentions-and-hashtags-in-a-tweet
function twitterify($ret) {
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
$ret = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $ret);
$ret = preg_replace("/#(\w+)/", "<a href=\"http://twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $ret);
return $ret;
}