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

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.

Related

Running a python script in a Gsheet button

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!

Saving javascript script output to file on server

So far Gurus here helped me a lot so far and I am back again with my little queries again.
I have a js that is being called from a webserver through a internal site I am taking care of. js has lots of very helpful debugging comments through
console.log($output)
that are being displayed on the console. I was wondering if there is any way i can redirect these comments to a log file on server.
I know it is hard but not impossible... I thought of doing something like
> exec 1>>${LOG_FILE}
but then it means it will get outputs from every file will be going to that file.
I only need the output from one file... is it possible?? plus do I need to run it through cron? because I don't have permission to change anything in js itself.
-Thanks

HTML / Javascript only recursive search?

I posted on a wishlist of a JS library that I wish their documentation search included results from more than just the titles of the pages. After I posted I realized that that may be difficult since when users download it from Github and use the docs on their local machine there is no server side code that will run such as PHP that could traverse the filesystem and parse all the results into an array, but before I just assume that there isn't a way to do it I thought I would ask.
When you look at this link: http://threejs.org/docs/index.html#Manual/Introduction/Creating_a_scene
If you type in anything that isn't part of the list on the left, it won't show up, such as if you type in goal nothing shows even though in the first sentence it says The goal of this section. Is there a way to put together a JS search that would traverse all the files that are on the list put the text into an array that could be searched without server side code?
I know Jquery would probably make the job easier, but I doubt he would include that in his repository, so as plain vanilla JS as possible would be preferred.

Create JavaScript with Umbraco

Do you know if there is a way to create a javascript or PHP file in Umbraco?
By this I mean that I would like to have the user populate fields in the same was as creating a page, but for it to output as .js or .php rather than the usual .aspx
Many thanks!
I don't see any reason why you couldn't; you could use a controller to output as pretty much anything by setting the mime-type.
I'd be wondering though what your use-case for generating PHP files would be though; the server would still need to process the PHP script somehow; which may not be a trivial task (unless you just want to generate the PHP file for download/display the code) as it isn't client-side script at all.
JavaScript on the other hand is entirely a different matter - as it's processed client-side you could just point the browser at a url that happens to deliver the generated JavaScript. You could even render the JavaScript out from a WebApi end-point and the browser client would quite happily consume it.

Web crawler: Using Perl's MozRepl module to deal with Javascript

I am trying to save a couple of web pages by using a web crawler. Usually I prefer doing it with perl's WWW::Mechanize modul. However, as far as I can tell, the site I am trying to crawl has many javascripts on it which seem to be hard to avoid. Therefore I looked into the following perl modules
WWW::Mechanize::Firefox
MozRepl
MozRepl::RemoteObject
The Firefox MozRepl extension itself works perfectly. I can use the terminal for navigating the web site just the way it is shown in the developer's tutorial - in theory. However, I have no idea about javascript and therefore am having a hard time using the moduls properly.
So here is the source i like to start from: Morgan Stanley
For a couple of listed firms beneath 'Companies - as of 10/14/2011' I like to save their respective pages. E.g. clicking on the first listed company (i.e. '1-800-Flowers.com, Inc') a javascript function gets called with two arguments -> dtxt('FLWS.O','2011-10-14'), which produces the desired new page. The page I now like to save locally.
With perl's MozRepl module I thought about something like this:
use strict;
use warnings;
use MozRepl;
my $repl = MozRepl->new;
$repl->setup;
$repl->execute('window.open("http://www.morganstanley.com/eqr/disclosures/webapp/coverage")');
$repl->repl_enter({ source => "content" });
$repl->execute('dtxt("FLWS.O", "2011-10-14")');
Now I like to save the produced HTML page.
So again, the desired code I like to produce should visit for a couple of firms their HTML site and simply save the web page. (Here are e.g. three firms: MMM.N, FLWS.O, SSRX.O)
Is it correct, that I cannot go around the page's javascript functions and therefore cannot use WWW::Mechanize?
Following question 1, are the mentioned perl modules a plausible approach to take?
And finally, if you say the first two questions can be anwsered with yes, it would be really nice if you can help me out with the actual coding. E.g. in the above code, the essential part which is missing is a 'save'-command. (Maybe using Firefox's saveDocument function?)
The web works via HTTP requests and responses.
If you can discover the proper request to send, then you will get the proper response.
If the target site uses JS to form the request, then you can either execute the JS,
or analyse what it does so that you can do the same in the language that you are using.
An even easier approach is to use a tool that will capture the resulting request for you, whether the request is created by JS or not, then you can craft your scraping code
to create the request that you want.
The "Web Scraping Proxy" from AT&T is such a tool.
You set it up, then navigate the website as normal to get to the page you want to scrape,
and the WSP will log all requests and responses for you.
It logs them in the form of Perl code, which you can then modify to suit your needs.

Categories

Resources