Google App Engine Live Updates (Python) - python

I was wondering if it would be possible to write an application using the Google App Engine and Python to create a basic calculator? However, the real question is would it be possible to have the calculator do the math without having to refresh the page?
To be more specific, I mean if there is an input box that a formula can be entered into (lets say for example the user inputs 2 + 2) and then the user clicks a submit button or calculate button, can the answer to the inputted problem be solved without the webpage having to refresh itself? If so, would it be possible to go about this without using AJAX? A very brief suggestion on how to go about this or a link to an application and its source code that updates things without refreshing the page would be greatly appreciated!
Thanks in advance for your answers!

To make a calculator in a browser that does not involve a page refresh, your best bet is to learn javascript. Searching google or stackoverflow for javascript tutorials will give you lots of options to work from. You don't need to learn python or App Engine to create the calculator. You could use app engine to serve the javascript, but you wouldn't need to write any python to just serve static content like that.

Using GAE you provide a real-time update with "Channels" http://code.google.com/appengine/docs/python/channel/
The Channel API creates a persistent connection between your
application and Google servers, allowing your application to send
messages to JavaScript clients in real time without the use of
polling.
Interesting enough for your purpose.

Related

How can I trigger a different script when a new google forms response is submitted?

I want to be able to run my own python script (which will basically just print out the response with a bit of formatting) whenever a new response is submitted to my google form. I looked at google's python API for forms, but it doesn't seem to have a way to set up a trigger so that the script executes when a new response is submitted. Best it can do is pull a response ID after the fact and give me the details of the response. Is there a way to do this? From what I've seen google's apps script can't do what I need it to (print stuff onto paper), so I would prefer to make a trigger for my own python script.
Any help appreciated. If the answer to this question is painfully obvious, please guide me in a good general direction because I'm totally lost.
Thanks!
You have to rethink your "solution" as the Google Forms API doesn't support triggers but Google Apps Script script does, i.e., you might make your Python program to poll the form or the linked spreadsheet.
From https://developers.google.com/forms
Automate Google Forms with simple code
Anyone can use Apps Script to automate and enhance Google Docs in a web-based, low-code environment.
Automate tasks based on Google Form submissions.

Creating a frontend program for a machine learning program (help)

I recently got a project that involves creating a front end application that would connect to a backend program. The backend program is a machine learning code that inputs some parameters and outputs a graph. This machine learning code was made in Python. The goal of the frontend program is for users over the web to input their data and parameters needed for the ML code to work and then receive back the graph to the front end for the users to save as a GIF or something similar.
I've never done anything of this level before, so I've been scouring the internet for answers. I've come to the answer that the front end will be html and some CSS and will connect to some API program which acts as the middle man between the front end and the backend programs. Is this the correct direction? Any references or YouTube videos about how to do something like this is greatly welcomed.
I've also looked into straight connecting from the frontend program to the ML code.
Thanks All!
So this is a very general question, hence it is hard to answer. I will give you a short pointer on how to achieve this, please note that there are many ways and I am trying to give you the easiest.
App requirements I assume:
The look is not important, functionality is the base
Any framework can be used
A beginner should be able to do this. - hence js frameworks will be avoided.
I've come to the answer that the front end will be html and some CSS and will connect to some API program that acts as the middle man between the front end and the backend programs.
Yes, this is somewhat correct, you most likely will sprinkle some JS into the frontend, but it is not required and everything is possible with just HMTL, CSS, and an API. In the frontend, you will need a <form> which will submit the input data as a post request to your API (a server). The API will then need to invoke the ML script/program and catch the resulting Image. Then you need to save the image on your server. Till now the frontend is still waiting for the request to finish so, your server has not returned anything!
Side note in a real project this would be bad because ML code can take a long time for execution and awaiting a request is caped and you could get a timeout error.
So your API/server receives the image and saves the image into a public folder which is exposed to the web, often called statics or public. Then you can redirect the user onto a second html page, which you can then dynamically render with a template language, e.g. Jinja2.
As backend technology, I would suggest that you use something which is not too opinionated because those usually take more weight from but are harder to learn. Therefore, look at Flask to build an API. For the frontend use https://getbootstrap.com/ so you do not need to write your own css. And as a template language use Jinja2.
to get yourself started I would recommend one of these sources:
https://www.youtube.com/watch?v=Z1RJmh_OqeA // Flask - explains Jinja2 as well
https://www.youtube.com/watch?v=qz0aGYrrlhU // html
https://www.youtube.com/watch?v=K-ccGZYRWzs // bootstrap froms

Deploy a Python application to web that interacts with local files

Background: Am comfortable in Python, know nothing about web deployment. I am looking into it as an alternative to compiling into .exe or .app for Win or Mac distributions.
Issue: I have a simple application that uses BeautifulSoup, openpyxl, and PySimplyGUI. It interacts with some local excel-files and creates new ones. I want to be able to, using minimum effort, make it accessible on my own web page or something similar, and make the created excel-files available for browsing/download. I have no idea how to do any of this. I've been looking into Flask and cloud foundry, but it feels like there should be some easy alternative that I'm missing. Ideally I would want a page where someone can log in (given a username and password I supply), which then directs to a page where the user can interact with my application.
Request: Is there a relatively easy way to do this that doesn't involve setting up a lot of stuff in html, etc., and where excel-files can still be interacted with by openpyxl? I ideally would just want some template, where I can "fill in the blanks" for the python method I would want to execute for each button!
Hope this makes sense. Thanks in advance :)
The easiest way to create a web app with a simple interface yet effective which does not require frontend programming is Streamlit. It is primarily used by data scientist to create simple web apps quickly.

Creating buttons in google docs spreadsheet like EXCEL

My question is quite simple but I can't figure it out. How can I create buttons in google docs spreadsheet which can be seen when logged in. I want to initialize the script upon logging into the google docs rather than going to load manually. Is there a way to do that? Also I couldn't find the nice tutorial which gives the intermediate knowledge about the google-docs function. All I could find was this simple tutorial. Another question is: Can the python script as provided by google-docs be saved and executed in google-docs itself? If it could, it can provide more functionality than simple google-functions. I am completely newbie to google docs so please bear with me.
You can create some UI elements using Google Apps Script.
https://developers.google.com/apps-script/guide_user_interfaces
Apps Script is javascript-like script that runs SERVER side, in google land. It has access to various services and google document model. But is otherwise restricted from many things that you'd think javascript can do. This is the root of most of its limitations. You can enable a script to load on start-up and hook into related events.
While there is Python and Java API to access Google Docs and their content, there is no way to to create the UI elements outside of Apps Script and the related UI Designer:
http://googleappsdeveloper.blogspot.com/2011/06/building-ui-in-apps-script-just-got.html

How to create a plugin for chrome so that it can read the web page's text and send it to python program?

I have a program written for text simplification in python language, I need this program to be run on a browser as a plugin... If you click the plugin it should take the webpage's text as input and pass this input to my text simplification program and the output of the program should be again displayed in another web page...
Text simplification program takes input text and produces a simplified version of the text, so now I'm planning to create a plugin which uses this program and produces simplified version of text on the webpage...
It will be of great help if anyone help me out through this...
You would need to use NPAPI plugins in Chrome Extension:
http://code.google.com/chrome/extensions/npapi.html
Then you use Content Scripts to get the webpage text, you pass it to the Background Page via Messaging. Then your NPAPI plugin will call python (do it however you like since its all in C++), and from the Background Page, you send the text within the plugin.
Concerning your NPAPI plugin, you can take a look how it is done in pyplugin or gather ideas from here to create it.
Now the serious question, why can't you do this all in JavaScript?
If you want an easier way than trying to figure out plugins, make it run as a webservice somewhere (Google App Engine is good for Python, and free), then use a bookmarklet to send pages from the browser. As an added bonus, it works with any browser, not just Chrome.
More explanation:
Rather than running on your own computer, you make your program run on a computer at Google (or somewhere else), and access it over the web. See Google's introduction to App Engine. Then, if you want it in your browser, you make a "bookmarklet" - a little bit of javascript that grabs the web page you're currently on (either the code or the URL, depends on what you're trying to do), and sends it to your program over the web. You can add this to your browser's bookmark bar as a button you can click. There's some more info on this site.

Categories

Resources