I have a python script that continuously generates JSON object
{ time: "timestamp", behaviour: 'random behaviour'} and display it on stdout.
Now I want to build a web app and modify the script so that I can read continous data to my web page. I donno where to start from.
Well in details: I want a web API to have an on/off button and by clicking on it start reading the beahviour and on clicking off it stops.
I am very new to programming so please suggest me topics and ways I need to study/ look upon to make this app.
thanks
Here's a simple way I'd go about doing it:
Create a backend service that exposes the python script's output via HTTP. You can use any familiar backend programming language: python, java, .net etc to host a simple http web server, and expose the data.
Create a simple html page, that makes an ajax call to your backend service, pulls the data, and shows it on the page.
Later add your buttons, make the page nicer, responsive on other devices.
Topics to read depends on what you are missing above. My best guess based on your question is that you are not familar with front end programming. So read up on html, js, css and ajax.
Related
I have a Python script that accepts text from a user, interprets that text and then produces a text response for that user. I want to create a simple web interface to this Python script that is accessible to multiple people at once. By this I mean that person A can go to the website for the script and begin interacting with the script and, at the same time, person B can do the same. This would mean that the script is running in as many processes/sessions as desired.
What would be a good way to approach this?
Maybe you should try a python web framework like django or flask .etc
Make a simple website that offers a webpage that contians a form to input text ,and when people visit the url, put their text in the form and submit, your code can handle it and return a webpage to show the result.
I wish to create a website to compute simple stress calculations for machine design. I have attached a sample below. What tools do I need to build something like what I have shown in the attached image. I want the user to perform the calculation, save for later use and print it in the form of a report. Please note the items in boxes are user input.
Looks like you want to create a web app. If your language of choice is python, you can use the Django web framework. Web frameworks like Django and Ruby on Rails help organize your files for websites. You can create a web app using Django but all your python code will be running on the server. Any calculations would need to be sent as a request to the server and returned to the client. JavaScript runs on the client computer and would be better for your application. You can also store cookie data in the client computer to access later. In addition you should know some html and CSS to display your app. The html, CSS and JavaScript can all be implemented in the Django framework.
There is a website that I frequently go to and play a browser game. I want to be able to have some kind of firefox plugin that can scrape data off of the page and send it to a python script. I want the controls for the program (toggle on/off) to be a HTML display which is added on to the webpage after every time I load it.
I am aware of plugins like Greasemonkey, but I don't want to use this because if I want to send any data to python, I have to setup a python http server and manually launch it every time I want to use my program.
Essentially this is what I want to be able to do:
Open Firefox as I would normally to do any kind of internet browsing
Go to the website which has my game.
The game is loaded, javascript code is executed which adds some basic HTML controls which can be used to toggle settings in my backend python program
If I choose to enable the program, javascript will parse the page when necessary and send that data to a python script on my machine.
The python program executes, recieves the data, and does what I want.
I feel like this should be a simple task, but I can't find anything straightforward. From what I have been reading, I can make a Firefox extension which can do this, but the tutorials I have seen are all for things like adding extra features to the browser. I just want a minimal tutorial since all I need to do is just run my own javascript when visiting website "X" and then call a python script.
I need to develop a simple login page using Python language with two fields and a button, like:
Username, Password, Login
I know there are some beautiful Python frameworks like
Django, Grok, WebPy, TurboGears
which support web development using Python, but mine is a basic requirement consisting of only 3 screens (pages):
1st page - Login page (Redirects to 2nd page when login button is clicked)
2nd page - Page with records in the form of a list, with an option for adding new records (Redirects to 3rd page when "Add Records" button is clicked)
3rd page - Page with fields, which are saved as records for the list on 2nd page (After entering details and clicking Submit)
So, I have decided to develop the above functionality using Python without using any framework, so that I can have flexibility as well as write my own code.
Is it possible to create a login page using Python without using a framework?
I haven't worked on web services and don't know the basics of web development in Python.
If possible, can you provide me an example on how to create a login page using Python and achieve the functionality described above?
Firstly, it's good to learn how to do things without the frameworks, but if you're doing this for anything but educational purposes it's most likely a mistake to say "my requirements are too simple to bother with frameworks." What you describe is on the simpler end of the spectrum, but already I can see some complications you're probably glossing over.
Anyway, to implement your 3 pages, you will need:
a web server
2 static HTML files
python handlers for GET on 2nd Page, POST from 1st and 3rd Page
storage (either flat file or database)
Look at A Simple Python CGI Server Tutorial to get started, and there are more details at TutorialsPoint: Python - CGI Programming.
Your HTML forms just need to have method="POST" and action set to the URL you're serving from python for each form. Your POST handlers should do what they need to do and then serve a 302 redirect.
If you don't know the basics of python web development, you're going to have your hands full and should probably start with a single user flat-file system. Maybe you can even get away with storing that in memory for now. Then if/when that stops doing it for you, try sqlite. Configuring web servers is a pain, too, so if you can just stick with BaseHTTPServer.
Finally, load your records in another python endpoint, make some HTML for each, slap it in a big string with surrounding HTML, and serve that puppy.
You requirement is very trivial. Though people may suggest micro frameworks like flask, bottle I would say you should try Django and have a look at Django Admin Panel. I think it's possible for you to meet your requirement using the Django admin feature.
Updated
Have a look at this http://docs.python.org/howto/webservers.html
Without a framework and if you don't want to mess with CGI you can take a look at http://webob.org/ .
As a newbie to app engine and python I can follow the examples given by Google and have created a python application with a template HTML page where I can enter data, submit it to the datastore and by reading back the data, just sent, recreate the sending page so I can continue adding data and store again. However what I would like to do is submit the data, have it stored in the datastore without the sending page being refreshed. It seems like a waste of traffic to have all the data sent back again.
Sounds like you want to look into AJAX. The simplest way to do this is probably to use the ajax functions in one of the popular Javascript libraries, like jQuery.
AJAX. If you want a specific resource concerning AppEngine -
http://code.google.com/appengine/articles/rpc.html (uses Python) is very good.
Here is a good link to understand Communication with Server on Google App Engine
Have a look at Pyjamas pyjs.org
It's a Python Compiler for web browsers. Write your client side in Python and Pyjamas will compile it into JavaScript.