Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.raspberry-pi > #9176
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Newsgroups | comp.sys.raspberry-pi |
| Subject | Re: web server that displays temp, humitdy etc |
| Date | 2015-07-22 18:15 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <moomku$5nh$1@dont-email.me> (permalink) |
| References | <ec97baf6-2ca7-4ec3-9b76-8445f2d23d59@googlegroups.com> <OVzrx.6890$vh6.5379@fx12.am4> <slrnmqu1bn.t4b.spamtrap42@one.localnet> <5c997b0a-9bf3-48e0-adcf-7cf52f6636c2@googlegroups.com> |
On Wed, 22 Jul 2015 04:33:45 -0700, Glen_Ossman wrote:
> Gents
>
> you gave me some good ideas that Py code can't be run by a web page
> Access denied you can only SUDO the code
>
That can most likely be fixed by sorting out the read and execute
permissions for the Python code file. Alternatively, follow what the
Apache manual says in the "CGI: Dynamic Content" manual about running
scripts.
> so i am thinking that root cron every 10 minuets and then read the file
> using html or PHP
>
If you do that, don't run it as root: no user programs should be given
that amount of access to the system.
Instead 'sandbox' it by making another user to run it in. The crontab
file you'll use to run it every 10 minutes has the ability to run
programs under any user you specify
When a new file has been created, you have two choices:
1) create it in the /home/pyuser/public_html directory (you'll have to
create that) and configure Apache to read the file from there,
2) copy the file to some place in the main Apache web page storage area.
In either case your script must set the output file's permissions so
Apache can read it.
> so i need a frame to run it in full page ? with the text on both sides
> pulled from the file ?
>
No, your Python code just needs to write a text file containing the HTML
needed to format the file, i.e it should start with:
<html>
<head><title>page title</title></head>
<body>
... the text and formatting that forms the page content goes here ...
</body>
</html>
Do yourself a favour by downloading and installing the 'tidy' package
("apt-get install tidy"). tidy is a program that, checks HTML pages for
errors and/or tidies up the HTML text. In this case its the fast way to
make sure your Python code is generating valid HTML. Running
"tidy -e myoutput.html" will report any problems with the HTML in
'myoutput.html' - using this while you're writing your program will be a
lot quicker (and find more gotchas) than looking at the HTML file in a
browser, though of course you need to look at the output with a browser
as well.
If you haven't got an HTML book yet and think you need one,
"HTML and CSS: Visual QuickStart Guide" by Elizabeth Castro is worth a
look. I have her "HTML for the World Wide Web" 5th edition and would
recommend that except that it deals with 2003 vintage HTML 4 while "HTML
and CSS" covers the current HTML 5 flavour.
> i think that will work?
>
Either running your Python program from Apache on demand or doing the 10
minute cron update should do what you want.
But, see how long the program takes to rebuild its webpage: if it takes
more than a second to do so, then running it on demand may give a
noticeable delay for the browser user while running it as a cron job
won't provided you run the Python from a shell script which does this the
following:
- run Python code to create the file with a name that Apache doesn't know
- use chmod to set the files permissions for Apache access
- use cp or mv to replace the old file with the new one
because this reduces the time needed to swap the file served up by Apache
to an absolute minimum.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Back to comp.sys.raspberry-pi | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: web server that displays temp, humitdy etc Glen_Ossman@ossman-cg.net - 2015-07-22 04:33 -0700
Re: web server that displays temp, humitdy etc Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-22 18:15 +0000
Re: web server that displays temp, humitdy etc mm0fmf <none@mailinator.com> - 2015-07-22 20:56 +0100
Re: web server that displays temp, humitdy etc David James <david@tcs01.demon.co.uk> - 2015-07-22 21:01 +0000
Re: web server that displays temp, humitdy etc Glen_Ossman@ossman-cg.net - 2015-07-22 14:11 -0700
Re: web server that displays temp, humitdy etc mm0fmf <none@mailinator.com> - 2015-07-22 22:33 +0100
Re: web server that displays temp, humitdy etc Glen_Ossman@ossman-cg.net - 2015-07-22 15:16 -0700
Re: web server that displays temp, humitdy etc Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-22 22:51 +0000
Re: web server that displays temp, humitdy etc Gordon Henderson <gordon+usenet@drogon.net> - 2015-07-23 17:11 +0000
csiph-web