Apr 24, 2020 10:00 AM
An extension of Example: Netflix-style UI with a script, here we use OMDB API in the Scripting Block, to grab the Runtime/Duration of a given film from a given Airtable:
Could of course be used with any API service, with a bit of adapting.
Todo:
for (let record of result.records.slice(0,1000)) {
May 06, 2020 06:41 AM
Hi Oli. Thank you so much for this script. Using this and the Netflix-style script to make my first steps with the scripts section (I have no background in programming, so this is all very learning by doing).
I was just wondering: can I use this also to call the RottenTomatoes score? I know how to make this work with simple values like Runtime, but does anyone know how to get the script to pick the Rottentomatoes Value from the ‘Ratings’ section of the OMDB API?
"Ratings":[{"Source":"Internet Movie Database","Value":"7.4/10"},{"Source":"Rotten Tomatoes","Value":"98%"},{"Source":"Metacritic","Value":"99/100"}],"Metascore":"99","imdbRating":"7.4","imdbVotes":"253,485","imdbID":"tt4975722",
Sorry if this question is a bit basic… these are my first baby steps working with these kind of scripts :slightly_smiling_face:
May 06, 2020 06:52 AM
Sure I have this in a script I can paste later today (2-3hr from now)
May 06, 2020 06:59 AM
Wow, thank you! That would be amazing!
May 06, 2020 09:18 AM
@MarvinW visit any webpage using Chrome, open DevTools (CtrlShiftC/CmdShiftC), click Console section, then paste in this code (with your own OMDB API key). It should demo the ratings nesting nicely. I used it in a first draft of this site I’m building which uses Airtable API for all its data https://bechdelrecommender.web.app
var myKey = [your OMDB API key];
var myFilm = "tt1285016";
var myRequest = "https://omdbapi.com/" +
"?apikey=" + myKey +
"&i=" + myFilm;
console.log("about to request from " + myRequest);
fetch(myRequest)
.then((myResponse) => myResponse.json())
.then((myJson) => {
document.write("<h1>" + myJson['Title'] + "</h1>");
var keys = Object.keys(myJson["Ratings"]);
for (const key of keys) {
// uncomment 2x lines to filter for ONLY Rotten Toms...
// if (myJson["Ratings"][key]["Source"] == "Rotten Tomatoes"){ // this one
console.log("ratings: " + myJson['Ratings'][key])
document.write(
"<p>" +
myJson["Ratings"][key]["Source"] +
": <strong>" +
myJson["Ratings"][key]["Value"] +
"</strong></p>");
// } // and this one!
}
}
)
Jun 14, 2020 02:34 PM
@MarvinW I think I misunderstood you, sorry my answer didn’t go in the right direction. I’m actually looking to solve the Same question you’ve posed and wanted to ask: any solution found? I’ve tried a couple different approaches (nesting via await async, and via fetch/promise) and neither is working. Very interested to know how you solved it.