Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #102130 > unrolled thread

show instant data on webpage

Started bymustang <mustang@NOMAIL.it>
First post2016-01-26 17:10 +0100
Last post2016-01-30 05:01 +0100
Articles 20 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  show instant data on webpage mustang <mustang@NOMAIL.it> - 2016-01-26 17:10 +0100
    Re: show instant data on webpage David Palao <dpalao.python@gmail.com> - 2016-01-26 17:38 +0100
      Re: show instant data on webpage mustang <mustang@NOMAIL.it> - 2016-01-26 18:26 +0100
        Re: show instant data on webpage David Palao <dpalao.python@gmail.com> - 2016-01-27 11:36 +0100
          Re: show instant data on webpage mustang <mustang@NOMAIL.it> - 2016-01-27 16:36 +0100
            Re: show instant data on webpage Joel Goldstick <joel.goldstick@gmail.com> - 2016-01-27 10:49 -0500
              Re: show instant data on webpage mustang <mustang@NOMAIL.it> - 2016-01-27 18:20 +0100
        Re: show instant data on webpage "Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de> - 2016-01-27 12:02 +0000
          Re: show instant data on webpage mustang <mustang@NOMAIL.it> - 2016-01-27 16:37 +0100
            Re: show instant data on webpage "Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de> - 2016-01-27 16:47 +0000
              Re: show instant data on webpage mustang <mustang@NOMAIL.it> - 2016-01-27 18:21 +0100
                Re: show instant data on webpage Grant Edwards <invalid@invalid.invalid> - 2016-01-27 17:51 +0000
                  Re: show instant data on webpage mustang <mustang@NOMAIL.it> - 2016-01-29 12:48 +0100
                    Re: show instant data on webpage Joel Goldstick <joel.goldstick@gmail.com> - 2016-01-29 07:34 -0500
                      Re: show instant data on webpage mustang <mustang@NOMAIL.it> - 2016-01-30 21:50 +0100
                        Re: show instant data on webpage Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-01-30 21:33 +0000
                          Re: show instant data on webpage mustang <mustang@NOMAIL.it> - 2016-01-31 20:19 +0100
                            Re: show instant data on webpage Joel Goldstick <joel.goldstick@gmail.com> - 2016-01-31 14:48 -0500
                              Re: show instant data on webpage mustang <mustang@NOMAIL.it> - 2016-02-21 18:36 +0100
    Re: show instant data on webpage Grobu <snailcoder@retrosite.invalid> - 2016-01-30 05:01 +0100

#102130 — show instant data on webpage

Frommustang <mustang@NOMAIL.it>
Date2016-01-26 17:10 +0100
Subjectshow instant data on webpage
Message-ID<n885p7$1el2$1@gioia.aioe.org>
I've built a sensor to measure some values.
I would like to show it on a web page with python.


This is an extract of the code:

file  = open("myData.dat", "w")

while True:
         temp = sensor.readTempC()
         riga = "%f\n" % temp
         file.write(riga)
         time.sleep(1.0)

file.close()

Until this all ok.
Then in PHP I read the file and show it on internet. It works ok but...
First problem. I've to stop the streaming with CTRl-C to load the PHP 
file because if I try to read during measurement I cannot show anything 
(I think because the file is in using).
How can I show time by time in a webpage the output?

[toc] | [next] | [standalone]


#102131

FromDavid Palao <dpalao.python@gmail.com>
Date2016-01-26 17:38 +0100
Message-ID<mailman.19.1453826317.2338.python-list@python.org>
In reply to#102130
2016-01-26 17:10 GMT+01:00 mustang <mustang@nomail.it>:
> I've built a sensor to measure some values.
> I would like to show it on a web page with python.
>
>
> This is an extract of the code:
>
> file  = open("myData.dat", "w")
>
> while True:
>         temp = sensor.readTempC()
>         riga = "%f\n" % temp
>         file.write(riga)
>         time.sleep(1.0)
>
> file.close()
>
> Until this all ok.
> Then in PHP I read the file and show it on internet. It works ok but...
> First problem. I've to stop the streaming with CTRl-C to load the PHP file
> because if I try to read during measurement I cannot show anything (I think
> because the file is in using).
> How can I show time by time in a webpage the output?
>
> --
> https://mail.python.org/mailman/listinfo/python-list

Is this an option?

open("myData.dat", "w").close()

while True:
    temp = sensor.readTempC()
    riga = "%f\n" % temp
    with open("myData.dat", "a") as f:
        f.write(riga)
    time.sleep(1)

Best

[toc] | [prev] | [next] | [standalone]


#102133

Frommustang <mustang@NOMAIL.it>
Date2016-01-26 18:26 +0100
Message-ID<n88a81$1nt2$1@gioia.aioe.org>
In reply to#102131
> open("myData.dat", "w").close()
>
> while True:
>      temp = sensor.readTempC()
>      riga = "%f\n" % temp
>      with open("myData.dat", "a") as f:
>          f.write(riga)
>      time.sleep(1)
yes great it works!thanks a lot!
Anyway to refresh temperature I've to recall anytime the php page.
My idea is to read for example the first line every x seconds...it 
should work.
Is it possible to use python and not php to plot data?

[toc] | [prev] | [next] | [standalone]


#102149

FromDavid Palao <dpalao.python@gmail.com>
Date2016-01-27 11:36 +0100
Message-ID<mailman.31.1453891019.2338.python-list@python.org>
In reply to#102133
2016-01-26 18:26 GMT+01:00 mustang <mustang@nomail.it>:
>
>> open("myData.dat", "w").close()
>>
>> while True:
>>      temp = sensor.readTempC()
>>      riga = "%f\n" % temp
>>      with open("myData.dat", "a") as f:
>>          f.write(riga)
>>      time.sleep(1)
>
> yes great it works!thanks a lot!
> Anyway to refresh temperature I've to recall anytime the php page.
> My idea is to read for example the first line every x seconds...it should
> work.
> Is it possible to use python and not php to plot data?
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list

I'm not sure to understand how you are using php, but indeed you can
use python to plot data (have a look at matplotlib, for instance) and
also to make dynamic web pages (Flask, django).

Best.

[toc] | [prev] | [next] | [standalone]


#102159

Frommustang <mustang@NOMAIL.it>
Date2016-01-27 16:36 +0100
Message-ID<n8ao5t$19t0$1@gioia.aioe.org>
In reply to#102149
> I'm not sure to understand how you are using php, but indeed you can
> use python to plot data (have a look at matplotlib, for instance) and
> also to make dynamic web pages (Flask, django).

Because I don't know how to do it in python.
So I've used php. But I prefer working in python.
>
> Best.
>

[toc] | [prev] | [next] | [standalone]


#102161

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2016-01-27 10:49 -0500
Message-ID<mailman.37.1453910212.2338.python-list@python.org>
In reply to#102159
On Wed, Jan 27, 2016 at 10:36 AM, mustang <mustang@nomail.it> wrote:

>
> I'm not sure to understand how you are using php, but indeed you can
>> use python to plot data (have a look at matplotlib, for instance) and
>> also to make dynamic web pages (Flask, django).
>>
>
> Because I don't know how to do it in python.
> So I've used php. But I prefer working in python.
>

Having previously written websites using php, and now a confirmed python
developer, you should know this:

Php, vbscript, perl, and perhaps other languages allow the interspersal of
code and html in the same file.  You can't do that with python.  So, if you
begin to wade into making websites with python you may be a little lost
until you grasp the concept of separating code from templates (the html
portion) and how you populate your templates with your code values.  Django
is a popular choice, but some like smaller frameworks like flask, and
others.

>
>> Best.
>>
>>
> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com/stats/birthdays

[toc] | [prev] | [next] | [standalone]


#102165

Frommustang <mustang@NOMAIL.it>
Date2016-01-27 18:20 +0100
Message-ID<n8au91$1kuj$1@gioia.aioe.org>
In reply to#102161
> Php, vbscript, perl, and perhaps other languages allow the interspersal of
> code and html in the same file.  You can't do that with python.  So, if you
> begin to wade into making websites with python you may be a little lost
> until you grasp the concept of separating code from templates (the html
> portion) and how you populate your templates with your code values.  Django
> is a popular choice, but some like smaller frameworks like flask, and
> others.

anyway I'm not interested in building website I've only to plot/show 
data collecting them from a sensor and plot them in a realtime graph 
(for example temperature).

[toc] | [prev] | [next] | [standalone]


#102152

From"Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de>
Date2016-01-27 12:02 +0000
Message-ID<dgrpviFa5qeU1@mid.individual.net>
In reply to#102133
mustang <mustang@nomail.it> wrote:

>> open("myData.dat", "w").close()
>>
>> while True:
>>      temp = sensor.readTempC()
>>      riga = "%f\n" % temp
>>      with open("myData.dat", "a") as f:
>>          f.write(riga)
>>      time.sleep(1)
>yes great it works!thanks a lot!
>Anyway to refresh temperature I've to recall anytime the php page.
>My idea is to read for example the first line every x seconds...it 
>should work.
>Is it possible to use python and not php to plot data?
You even could use python for the webserver. Read the docs for the module
"SimpleHTTPServer".


[toc] | [prev] | [next] | [standalone]


#102160

Frommustang <mustang@NOMAIL.it>
Date2016-01-27 16:37 +0100
Message-ID<n8ao85$19t0$2@gioia.aioe.org>
In reply to#102152
> You even could use python for the webserver. Read the docs for the module
> "SimpleHTTPServer".
now I'm using apache. Is it possible to do the same with python+apache 
or it's better to use SimpleHTTPServer?

[toc] | [prev] | [next] | [standalone]


#102163

From"Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de>
Date2016-01-27 16:47 +0000
Message-ID<dgsallFeeu7U1@mid.individual.net>
In reply to#102160
mustang <mustang@nomail.it> wrote:

>> You even could use python for the webserver. Read the docs for the module
>> "SimpleHTTPServer".
>now I'm using apache. Is it possible to do the same with python+apache 
>or it's better to use SimpleHTTPServer?
mod_python exists for apache. If your only goal is just a simple website for
your temperature sensor you could do it completely with python. If the
webserver should serve other pages as well I'd prefer apache with mod_python.

[toc] | [prev] | [next] | [standalone]


#102166

Frommustang <mustang@NOMAIL.it>
Date2016-01-27 18:21 +0100
Message-ID<n8aub2$1kuj$2@gioia.aioe.org>
In reply to#102163
> mod_python exists for apache. If your only goal is just a simple website for
> your temperature sensor you could do it completely with python. If the
> webserver should serve other pages as well I'd prefer apache with mod_python.
>
my goal is only to collect data and show them or plotting in a graph.
So if I can do it only in python better!

[toc] | [prev] | [next] | [standalone]


#102168

FromGrant Edwards <invalid@invalid.invalid>
Date2016-01-27 17:51 +0000
Message-ID<n8b02r$fa0$1@reader1.panix.com>
In reply to#102166
On 2016-01-27, mustang <mustang@NOMAIL.it> wrote:
>
>> mod_python exists for apache. If your only goal is just a simple website for
>> your temperature sensor you could do it completely with python. If the
>> webserver should serve other pages as well I'd prefer apache with mod_python.
>
> my goal is only to collect data and show them or plotting in a graph.
> So if I can do it only in python better!

Then I'd use gnuplot or matplotlib.

-- 
Grant Edwards               grant.b.edwards        Yow! Where does it go when
                                  at               you flush?
                              gmail.com            

[toc] | [prev] | [next] | [standalone]


#102226

Frommustang <mustang@NOMAIL.it>
Date2016-01-29 12:48 +0100
Message-ID<n8fjiv$age$1@gioia.aioe.org>
In reply to#102168
> Then I'd use gnuplot or matplotlib.
>
ok, but then I can upload/plot them online?

[toc] | [prev] | [next] | [standalone]


#102228

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2016-01-29 07:34 -0500
Message-ID<mailman.83.1454070870.2338.python-list@python.org>
In reply to#102226
On Fri, Jan 29, 2016 at 6:48 AM, mustang <mustang@nomail.it> wrote:

>
> Then I'd use gnuplot or matplotlib.
>>
>> ok, but then I can upload/plot them online?
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Confusing mustang.  You said:

anyway I'm not interested in building website I've only to plot/show data
collecting them from a sensor and plot them in a realtime graph (for
example temperature).

and then you said:

ok, but then I can upload/plot them online?

So, the python plotting packages mentioned can create files that hold your
graphs.  As to whether you want to display them on the web or send them
around as attachments to your coworkers, or build some local application to
display them is your choice

-- 
Joel Goldstick
http://joelgoldstick.com/stats/birthdays

[toc] | [prev] | [next] | [standalone]


#102310

Frommustang <mustang@NOMAIL.it>
Date2016-01-30 21:50 +0100
Message-ID<n8j7mb$1unq$1@gioia.aioe.org>
In reply to#102228
> So, the python plotting packages mentioned can create files that hold your
> graphs.  As to whether you want to display them on the web or send them
> around as attachments to your coworkers, or build some local application to
> display them is your choice
>
Sorry for my confusion :D
I'm still not sure wht to do.
Anyway I would like to plot graph with my data first of all, then I 
could think to share them in network and then online.

[toc] | [prev] | [next] | [standalone]


#102312

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2016-01-30 21:33 +0000
Message-ID<mailman.138.1454189623.2338.python-list@python.org>
In reply to#102310
On 30/01/2016 20:50, mustang wrote:
>
>> So, the python plotting packages mentioned can create files that hold
>> your
>> graphs.  As to whether you want to display them on the web or send them
>> around as attachments to your coworkers, or build some local
>> application to
>> display them is your choice
>>
> Sorry for my confusion :D
> I'm still not sure wht to do.
> Anyway I would like to plot graph with my data first of all, then I
> could think to share them in network and then online.

How about https://plot.ly/python/ ?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#102364

Frommustang <mustang@NOMAIL.it>
Date2016-01-31 20:19 +0100
Message-ID<n8lmol$192a$1@gioia.aioe.org>
In reply to#102312
> How about https://plot.ly/python/ ?
>
Free versione: Create 1 private chart
And if I've 3 sensor with 3 different plots?

[toc] | [prev] | [next] | [standalone]


#102365

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2016-01-31 14:48 -0500
Message-ID<mailman.172.1454269734.2338.python-list@python.org>
In reply to#102364
On Sun, Jan 31, 2016 at 2:19 PM, mustang <mustang@nomail.it> wrote:

>
> How about https://plot.ly/python/ ?
>>
>> Free versione: Create 1 private chart
> And if I've 3 sensor with 3 different plots?
> --
> https://mail.python.org/mailman/listinfo/python-list
>

You need free and private?  The price is low -- if this is a business why
not pay?  If not a business, why private?

There is another charting library called pygal which is great.  It can
produce output to .svg file format or .png.  You could distribute the files
which will display in a browser.  Or you could build them into web pages if
you are so inclined to build a website.  It seems that isn't what you want
to do.  You could also upload images to some free image site. Photobucket
supports .png images.  pygal can create .png images



-- 
Joel Goldstick
http://joelgoldstick.com/stats/birthdays

[toc] | [prev] | [next] | [standalone]


#103309

Frommustang <mustang@NOMAIL.it>
Date2016-02-21 18:36 +0100
Message-ID<nacsio$1utg$1@gioia.aioe.org>
In reply to#102365
> You need free and private?  The price is low -- if this is a business why
> not pay?  If not a business, why private?

it's not business it's like a school project, so no money :D

> There is another charting library called pygal which is great.  It can
> produce output to .svg file format or .png.  You could distribute the files
> which will display in a browser.  Or you could build them into web pages if
> you are so inclined to build a website.  It seems that isn't what you want
> to do.  You could also upload images to some free image site. Photobucket
> supports .png images.  pygal can create .png images
>
>
>
ok thanks.

[toc] | [prev] | [next] | [standalone]


#102274

FromGrobu <snailcoder@retrosite.invalid>
Date2016-01-30 05:01 +0100
Message-ID<n8hcd0$ear$1@dont-email.me>
In reply to#102130
On 26/01/16 17:10, mustang wrote:
> I've built a sensor to measure some values.
> I would like to show it on a web page with python.
>
>
> This is an extract of the code:
>
> file  = open("myData.dat", "w")
>
> while True:
>          temp = sensor.readTempC()
>          riga = "%f\n" % temp
>          file.write(riga)
>          time.sleep(1.0)
>
> file.close()
>
> Until this all ok.
> Then in PHP I read the file and show it on internet. It works ok but...
> First problem. I've to stop the streaming with CTRl-C to load the PHP
> file because if I try to read during measurement I cannot show anything
> (I think because the file is in using).
> How can I show time by time in a webpage the output?
>

Perhaps you could use a Javascript plotting library (like the one at 
flotcharts.org), and use Python only as a CGI agent to serve plotting 
data when requested by Javascript, at regular intervals?

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web