javascript - can anyone offer help on how to make this code more efficient? -
I am very new to coding, so please forgive me a newbie mistakes made by me. Any and all help is appreciated!
By using the GVT API, I was able to drag images from the Flix database and was able to put them in a spread sheet, but my used process seems to be unnecessarily painstaking.
Here is the function that I used to draw the image URL from the database:
function kwURL (keyword) {var response = UrlFetchApp.fetch ("https: / /www.flickr.com/search/?q= "+ keyword) var content = response.getContentText (); Var length = content.length; Var calculation = 0; (Var i = 0; i & lt; = length -3; i ++) {if (content.substring (i, 5 + i) .equals ("src = \" ")) {var start = I + 5 ; Count + 1 (if (content.substring (e, e + 1) .equals ("\" ")) {var end = 1} (count == 4) {for (var e = start; e & lt; Length-1; e ++) e break;}}} If (calculation == 4) {break;}}} Logger.log (content.substring (start, end)); return content.substring (start, end) :} The fourth image, like the logo page and the luggage, from the first three, chooses the fourth image.
Here is the code that draws the word from the first column and flicker database Finds keywords in and the image found in the second column Contains:
function on change () {var sheet = SpreadsheetApp .getActiveSheet (); Var rows = sheet.getDataRange (); var numRows = rows.getNumRows (); (Var {Var keyword = sheet.getRange (i, 1) .getValue (); if (keyword! = "") {Sheet.insertImage (kwURL) for i = 2; i & lt; = numRows + 2; i ++) (Keyword), 2, i);}}} I could not find another program that was trying to do the same thing in Google Apps Script documentation or programs Which I searched on the internet, so hopefully someone has this dirty code Made it clear that I have made from scratch.
Use of screen-scraping (which is essentially what you are doing here) Should be done in the form. Any changes in the web page you are bringing may possibly break your code. A better way to solve your problem is to use a publicly available API for third-party developers who are requesting some data in a standard format. And it looks like Flickr: (Note: I have no experience with this API. I just found out that it exists after a quick Google search).
If you get the proper API resource, then you should be a JSON object with a list of URLs pointing back to the images directly. or if there is any other weird loops for loops, or something else ugly (magicString == '\ "src \"' ') or > (magicNumber == 4) / Code> Code At that time it should be very simple to include these pictures in these spreadsheets.
Comments
Post a Comment