Last active
May 23, 2022 16:44
-
-
Save dtw/044f76a637fd5c75912908c88922b14a to your computer and use it in GitHub Desktop.
Filter code to process an RSS Trigger into a Webhook to micropub via IFTTT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The title is of the form "Movie Name, YYYY - ★★" | |
let varEntryTitle = 'Jurassic Park III, 2001 - ★★★' | |
// This is the URL for the user's review | |
let varEntryUrl = 'https://letterboxd.com/username/film/jurassic-park-iii/' | |
// Entry content | |
let varEntryContent ='<p><img src="https://a.ltrbxd.com/resized/film-poster/5/1/7/3/1/51731-jurassic-park-iii-0-500-0-750-crop.jpg?k=d0966124ec"/></p> <p>Fine.</p>' | |
// Find the final dash to separate the movie title from the star rating | |
let varDashIndex = varEntryTitle.lastIndexOf('-') | |
// This is the star rating | |
let varRating = varEntryTitle.substring(varDashIndex+2) | |
// This is the movie title | |
let varTitle = varEntryTitle.substring(0,varDashIndex-1) | |
// remove username from the review URL to get the movie url - assume username allows 0-9, a-z, - and _. | |
const reg = /(?<=https:\/\/letterboxd\.com\/)[a-z-_]*\/(?=film\/.*)/ | |
// This is the URL for the movie on Letterboxd | |
let varMovieURL = varEntryUrl.replace(reg,'') | |
// Update the content a bit | |
let varHTMLContent = varEntryContent.concat('<br>',varRating,'<br><a href="',varEntryUrl,'">My review</a>') | |
varHTMLContent = varHTMLContent.replace('"','\"') | |
let varJSONBody = ''.concat('{"type": ["h-entry"],"properties": {"content": [{ "html": "',varHTMLContent,'"}],"watch-of": ["',varMovieURL,'"]}}') | |
//MakerWebhooks.makeWebRequest.setBody('{ "type": ["h-entry"], "properties": { "content": ["Micropub test of creating an h-entry with a JSON request via IFTTT"] } }') | |
MakerWebhooks.makeWebRequest.setBody('{ "type": ["h-entry"], "properties": { "content": [{"html":"<p>Micropub test of creating an h-entry with a JSON request via IFTTT</p><br>}] } }') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment