Launching Python script from Google Apps Script - javascript

I've been searching for some time, and, as I couldn't find an answer, I'm asking this one. My issue is quite simple:
I have a form linked to a sheet. Bound to this sheet, I have a script running, performing calculations based on the just inserted data, and taking actions. Although, I would like to perform a request on a given API. For so, I have a working script in python (something about 100 lines), and I'm not willing to rewrite it in JS (and I don't even know if that would be possible, considering some limitations on Google Apps Script JS), nor do I want to pay for Google App Engine.
Is there anyway to run an external file, like a DOS command line, from my script in Google Apps Script?
I've seen something similar here, but this doesn't fit my cases because the asker is willing to use GAE.
Thanks in advance!

No. You'll either have to run the python app in a 3rd party service and then call it from GAS using UrlFetch(); or call a GAS function from python using Google's execution API. I don't think there's any other way.

Related

use of google script editor

Hey so currently working on my first personal project so bear with the questions!
Currently trying to create a Javascript program that will parse info from google forms to produce slides displaying the info. So far from my research the best way I've found to facilitate this process is googles app script editor. However, I was wondering if I can run this code by requesting it from a different javascript (or maybe even java) program that I will write code on webstorm. If I cant do this what is the best way to utilize the google apps script editor?
Thanks!
Google Apps Script is just javascript with extra built-in APIs (like SpreadsheetApp, FormApp, etc.).
It also has a UrlFetchApp API.
So you can run code like this:
// The code below logs the HTML code of the Google home page.
var response = UrlFetchApp.fetch("http://www.google.com/");
Logger.log(response.getContentText());
As such, if you want to provide JavaScript from elsewhere, you could fetch it and then eval it on the Google Apps Script side. (but we all know how tricky eval can get)
One other option is to have your own server side written using Google App Engine (or any other framework) and use Google's OAuth and authorize your app to fetch data from the Forms form
Slides and Google Apps Script
You might like to take a look at the addon "Slides Merge" by Bruce McPherson. I've never used it but it sounds like it might work for you. Here's what it's looks like in the addon store:
Getting information from Google Forms is a snap with google apps script since your can link the form right up to a spreadsheet. The Google Apps Script documentation is really quite good these days. Here's the documentation link. Google Apps Script is loosely based on Javascript 1.6. If your already a programmer my guess is that you'll have few problems learning to use it. In my experience the most difficult thing was dealing with the arrays of arrays produced by the getValues() method of ranges in google apps script and I made a short video that might be of some help to you.
I also have a script that I wrote in Google Apps Script that produces a sheet show that is a slide show inside of a spreadsheet.
I've found that using the Script Editor is pretty easy. There's some documentation in the support section of the documentation. It can be a bit buggy at times but overall I think it's a pretty good tool.

Implementing Google Maps API Key into Java Project using Vaadin

I have taken over a an ongoing project that is written in Java (something that I have no prior experience with, but I can code Python and C++) using Eclipse (which I am also new to). The project uses Vaadin components, and Eclipse runs it with glassfish which pops up a page in the browser with the results.
I have been successful in navigating myself around the code and made a few modifications, however one of them is a tiny Google Map with markers and I have having trouble displaying it. The previous owner has already set up a Google Maps API for it. When I run the code in Eclipse, the result appears with a link that starts with "localhost:8080..." which does not display the Google Map ("Oops something went wrong. This page didn't load Google Maps correctly. See the Javascript console for technical details."). The API become accessible to the component when I switch "localhost" with the IP of the computer, and the map displays.
I am trying to replace the API key of the previous owner of the project with one that I have just acquired here at Google Developers Console. While I have also searched and found many examples that are very similar to this one, I cannot locate any javacript files within the project via Eclipse that I can apply the solution with.
With the ultimate goal for this is to host the exported .war file on a server, any help on how to locate the link between the code and the API key is much appreciated.
Thanks
I suggest you use this semi-official addon instead of trying to roll your own. It allows you to give the API key directly in the component constructor.
You should check out the Vaadin add-on directory for other needs as well, it has hundreds of useful addons for many purposes.

How to manage JavaScript scripts called from a Delphi application?

I have a program that leverages Google Maps from embedded JavaScript in Delphi (XE6).
I send it with TWebBrowser's HTMLWindow2.execScript method. I have many external calls and call backs using COM.
The constant to house the JavaScript is over 400 lines and is becoming nearly unmanageable. Since the JS is one string, the returned error offers little help. Many times, I have searched for a typo of out of scope var for hours.
I do use another editor, JetBrains, for my raw JS and that helps, but now I have to spend most of my time in Delphi IDE, to do the External stuff.
I was wondering if there is a better way to manage the script in Delphi?

Unable to see complete scraped web page in Google Apps Script logs

A few weeks ago I started learning Javascript and the Google Apps Script API, specifically in regard to spreadsheets. I have been trying to make a spreadsheet that fetches web pages and pulls stats about my friends for the game League of Legends. However, I have been running into a problem with the site I want to use, which is basically the only free LoL stats site that updates frequently. I'm not familiar at all with web development, but it seems when I try to access a page on lolking.net, for example http://www.lolking.net/summoner/na/60783 with Google's UrlFetchApp.fetch() it does not load the dynamic page. So instead of the final source, I get this which doesn't help me. Is there an easy way around this or would I simply have to use another website?
Thanks for thie info! Although it turns out I was mistaken. The UrlFetchApp was indeed returning the full source code, but I was using GAS's Logger to view the text. It seems the Logger has a length limit, so when I searched for the stats I wanted they weren't there simply because the source code got truncated. So, due to an oversight on my part, I never had a problem in the first place. For other people reading this question, in the end I have no idea how UrlFetchApp works with dynamic pages using clientside js (you'd probably want to talk to the poster below or post a new question).
You are getting fhe raw html page with clientside js included. That wont work from any system not just gas. You need to debug that page js and find where it does an ajax call to get the data you want.
Then do the same from your gas. Might not work if the call is authenticated etc.

Scraping dynamically generated html inside Android app

I am currently writing an Android app that, among other things, uses text information from websites which I do not own. In addition, some of the pages require authentification.
For some pages I have been able to log in and retrieve the html code using BasicNameValuePairs and an HTTPClient with its associated objects.
Unfortunately, these methods retrieve the webpage source without running any javascript functions that a browser (Android Webview even) would normally run. I need the text that some of these scripts are retrieving.
I've done my research, but everything I've found is guesswork & extremely confusing. I'm okay with ignoring pages that require login for now. Also, I am willing to post any code that may be useful for constructing a solution; It is an independent project.
Any concrete solutions for scraping the html result from javascript calls? An example would be absolutely top-notch.
Final Success:
Rhino. Used this jar file.
Other Things I Tried:
HttpClient provided by Android
Cannot run javascript
HtmlUnit
4 hours, no success. Also huge, added 12 mb to my apk.
SL4A
Finally compiled. Used THIS guide to set-up. Abandoned as overkill for a simple rhino jar.
Things That Might Work:
Selenium
Further results will be posted. Others results will be added if posted.
Note: many of the options listed above reference each other. I think rhino is included in both sl4a and htmlunit. Also, I think htmlunit contains selenium.
The aforementioned solutions are very slow and restrict you to 1 url (well, not really, but I dare you to scrape 10 urls with Rhino while your user is impatiently waiting for results).
An alternative is to use a cloud scraping solution. You get the benefit of not wasting phone bandwidth on downloading content you won't use.
Try this solution: Bobik Java SDK
It gives you the ability to scrape up to hundreds of sites in a matter of seconds

Categories

Resources