Running a python script in a Gsheet button - javascript

I want to use Gsheets to track accounts and group membership in a proprietary 3rd-party application. Right now I have a python script running on a server that checks the sheet for accounts and membership parameters and it works great. It will read the sheet and check the 3rd-party app and make sure they always match with the sheet being the source of truth.
However, I'm not really a Gsheet master. Recently I found that I can create buttons in Gsheets that will run JS code. I'm also not a JS master, however.
I actually have two questions. The first one I think the answer is yes. Can I hit outside resources like REST endpoints from these buttons?
If I am right and that can work. The second question is, can I have a JS script inside a button run a python script that I contain in the Gsheet somehow?
The reason is that this would make the entire process contained in the Gsheet for much easier distribution and adoption as it eliminates the need for ancillary resources to run the Python code.
Any help would be much appreciated!
Thanks!

Related

How to implement fulltext search for offline website

I need a client-side fulltext search for big offline website. The site is opened by browser. I've made a research and found some solutions - fullproof, fuse.js, flexsearch.js, elasticlunr.js. I searched for js libs, because as i inderstand, it's the single solution (please correct me if i'm wrong).
Also i can't clearly understand some moments:
As i know, browsers due to security policy block all scripts' execution from javascripts files. I couldn't run examples from fullproof git because of this problem, but i managed to run flexsearch example, because script execution was included in html code with tag. Can i implement some search system for my local website because i don't use any local server for hosting (like xampp)?
From documentation for different js libs i undestand, that all they use for indexing either variable with list of key words or json file. Maybe i have a luck of information, but how i can use search system to find words/expressions from the whole website (it has a main page and a lot of included pages with information)? Do i have to create some sort of database or some json file?
I'll be very grateful for your answers, explanations, solutions or maybe examples about this problem, thank you!
Try using Tipuesearch, they have a very simple mechanism for implementing offline search in your website...Visit their site, download al lrequired repositories and follow the instructions to add the search functionality to your website...
I have implemented it with success in a sample movie website i was designing and the searches can be modified to come with images...
https://directory.fsf.org/wiki/Tipue-Search
Firts of all, browsers doesn't block js scripts execution. Secondly, i managed to find two ways to solve my problem - keywords search and fulltext search: 1) I created a database with keywords (json file) and used flexsearch library to search in this database. Example of usage u can find on their website, either an example of json file. 2) This time i created a database (json file), in which one recording is a text content of a website. Then again i used flexsearch to find a word in this database. After appropriate site was found, it opened up and the searched word was highlighted (u can find such js libraries in net). All the solutions don't require any internet connection and can be used for offline websites.

Getting Custom Widgets, Static Javascript, and Voilà to all play nicely with each other in Jupyter Notebook

I’ve been working on a Jupyter Notebook for the last month and put together a very nice toolkit for my DevOps team out of it. I want to be able to containerize this tool, or at least host it on our own intranet, so that the rest of the team can use it without having to go through a long install/configuration sequence on their own machines. Voilà seems to be the best tool for doing that, as my tool uses the Python kernel extensively and this seems to be a way to host it on a remote machine while still retaining the ability to use the kernel.
My tool involves a couple of custom widgets. They’re very simple and there to communicate information better through the UI - they’re an image object and a label object that can slowly fade out over the course of several seconds to indicate that an operation (such as saving) was either recently completed or done so long ago that the information is likely no longer relevant. (I don’t want the user to see a ‘Data saved!’ message from 15 minutes ago, for example.) I managed to put these custom widgets together just fine - but like all custom widgets, they needed additional Javascript code to display on the Notebook.
Putting the relevant javascript in a cell with the ‘%%javascript’ magic tag causes the custom widgets to work perfectly - however, I do not want to rely on this as a long-term solution for two reasons. One reason is that I want the javascript to be able to be easily rewritten, stored to a repository, and viewed on tools outside the notebook itself - I don’t want to commit a new version of the notebook every time I need to change the Javascript, and I certainly don’t want to go digging through the .ipynb file when I want to read the code itself.
The other problem is that Voilà does not seem to support the ‘magic %%Javascript’ tag, at least at the moment. Putting the javascript code inside a cell before the cell containing the application and then running the entire notebook through Voilà does not seem to execute the Javascript code, only injecting it into the HTML - errors pop up throughout the Javascript console, and all of my custom widgets fail to render.
Is there some accepted way to create a Javascript file, one that would be kept in a /static folder or something like that to match up with images and HTML files, and then configure some Python code so that the Javascript file is imported and executed at the very least before my application’s widgets are created? I’ve looked at the custom.js option inside the root Jupyter settings, and would like something more local to the project if at all possible. I’ve also tried to move the files I created into an existing /static folder inside Voila and import them in the template with the following lines of code:
<script type=“text/javascript” src="{{resources.base_url}}voila/static/image_extra_features.js"></script>
<script type=“text/javascript” src="{{resources.base_url}}voila/static/label_extra_features.js"></script>
But this seems to just include, but never actually execute, the relevant code.
I’m sure I must be missing something. (I thought I found something promising when I chased the ’ _view_module_version’ section of the Python model of the custom widget down, as the version of the custom widget isn’t specified anywhere in the Javascript file, but that seemed to be a dead end- where is the module version supposed to be listed? Is it only in the Python file?)
Does anyone have any idea as to what could be the issue?

How to I turn a python script into a web app?

Sorry for the noob question, but I created a script that web scrapes data off our sccm server and compares it to programs that need to be pushed to hostnames.
My script works perfectly when I run it in pycharm, but I would now like to make this program available to the other guys on my team via webpage, instead of them needing to borrow my computer everytime, LOL!
Is there a way I can use a javascript front end to let them enter their username, password and serial number, and than based off that info run my script?
I'm not a programmer to be honest so I apologize if this seems like a straightforward thing.
This would be difficult for someone to just 'answer' but maybe a rough outline could help?
I'm certainly no professional but this is the way I might approach the issue.
create HTML/CSS/JS front end page with a form
upon clicking the 'submit' button have the JS take form data and export it into a JSON (just did a quick search on 'execute python script on button click' and things like that to find some implementations of the idea)
pass the JSON from the page onto the server and have the python script open up the JSON for the arguments it needs to use
python 'wraps' the results up into a JSON file and gives it back to the front end where you have another JS script that unpacks the JSON file and gives it to the user requesting the info. Alternatively, you could have Python put the data into some sort of excel sheet or csv or whatever and have python email the results to the user.
Once all done you'd simply have an instance of Python and all the appropriate libraries sitting on the server ready to use. Pycharm is simply an editor for code. You could theoretically install python itself, and the appropriate libraries needed for your code and just give your folks the .py file itself and have them run the script out of CMD/Terminal and achieve the same result.
Like I say, no professional by any means, and I'm sure I skipped a couple steps but that's a general outline. Obviously in the forms you'd wanna have validation and such to make sure the appropriate data gets used to avoid errors.

Multiple ExpressJS(Nodejs) Apps on Same Box

I've been searching for a straightforward way of doing this that wouldn't involve editing every single users' host file.
I'm going to have a couple internal apps for employees to use that are going to be hosted on the same Windows Server. I want to use a default port, but want them to be separated out so, for example if you go to
www.host.com/longrunners
you get the longrunners page. If you go to:
www.host.com/databaseMove
you get the database move page.
I'm aware that I could do this by having all of the code within the same server.js file, using app.get('/longrunners',function(res,req){}) etc for each separate app -- but I'm hoping there is a more modular solution. Maye a way to have one master server.js file that references the different apps?
Thanks!

What is the "acceptable" upper limit for JavaScript array size?

I left this question as generic as possible, but I do have a specific problem that I need to solve in my application and the answer to this would help.
The application I am working on uses PHP/MySQL as its backend, and is set up so that no text/words/phrases visible to the user are hardcoded in the HTML/JS that is output to the browser, rather they are stored in a database table associated with a language key that is used to fetch the correct translation of the word/phrase based on the user's language preference. Now this works great for text that exists inside the application's HTML, but in order for this system to work with the javascript files, all javascript must be placed in a .php file and wrapped in <script></script> tags and included inline with the HTML, CSS ect.
This creates some problems with the flexibility in the system's javascript, as it cannot be included as external scripts via <link> tags (I guess unless you set the .php file's headers manually), and perhaps more importantly it cannot be minified/packed etc. when served in the production environment.
My first thought of a solution to this problem is to have a php script that's placed before any other javascript which loops through every record in the language database table and creates an associative javascript array using the language key as the array keys and setting their value to the translated phrase according to the user's preference. So, in this way all javascript files could be made into actual .js files and link'ed, minified, packed, etc. as needed, and they would just reference the phrases they need from the master language array that was created (i.e. alert(LANGUAGE.some_text);)
Only problem is, the number of elements in this array could easily get into the thousands possibly even bigger. So back to my original question, what is an acceptable max size for a javascript array, based on the average PC? Or am I attacking this problem entirely wrong to begin with?
I think the problem has less to do with how much data javascript can theoretically handle and more to do with how your application is handling the data.
It sounds like you're returning all of the phrases for the user's language on every page, not just the phrases they need on that particular page. If that's the case, fixing it will be part of the solution to your problem.
The rest of the solution will be not using javascript for anything until the app is completely functional. Then go back and do progressive enhancement stuff with js.
Instead of generating javascript from those database queries, generate pages (server-side) in the user's natural language, and serve them from a separate subdomains/subdirectories. Have your web server load the appropriate config for the user's language based on subdomain/subdirectory.
It's not the answer you were looking for, but I hope it helps.
JavaScript is by its nature a scripting language. The interpreter is nestled inside the browser's kernel. Correct me if I'm wrong, but I don't believe there is a definitive upper limit. The only thing that constricts an unlimited upper bound are memory constraints.
You can house gigs of uncompressed data (more if you compress it).
You're more likely to get one of the top errors in the list here, before you'll see any "upper bound limit reached."
in order for this system to work with the javascript files, all javascript must be placed in a .php file and wrapped in tags and included inline with the HTML, CSS ect.
This creates some problems with the flexibility in the system's javascript, as it cannot be included as external scripts via tags
Actually, not necessarily true. You can serve javascript files (not html) using PHP. Of course doing this most likely mean that all your javascript file will have the extension .php but that is a small matter. If you don't care about being strictly correct you don't even have to set the Content-type to js since browsers will treat anything served by <script> tags as javascript anyway.
A lot of sites actually do this, though not necessarily in PHP. Google, Yahoo etc often serve javascript using a server side scripting language to enable them to do any or all of the following:
automatically concatenate javascript/css files into a single file
automatically minify the javascript/css files
automatically obfuscate the javascript files
automatically do dependency resolution to source needed javascript files
Some people use mod_rewrite to rename the .php (or .pl or .cgi) files to .js to hide the details of the implementation. But it's strictly not necessary.
Here's an example bookmarklet that I serve as a .php file.
I tried solving a similar problem as a non-web programmer before, and ended up hosting the language package as a separate XML which JS queries into. Bad idea, and I'll tell you why. Google can't see pages filled dynamically with JS. But if that's no issue to you, I would recommend that way, simply because I don't know any other. :)
The method Array.prototype.push , append arguments to the end of the array, and return the new length.
In some JavaScript engine such as v8, the length is bounded to 32bit unsigned integer, so this might be the limit you want to know.

Categories

Resources