fogmajor
Posts: 8
Joined: Fri Oct 25, 2013 8:24 pm

Single Webpage

Fri Oct 25, 2013 8:34 pm

I have been having such fun with my pi and have spent many a late night failing and then succeeding.
I just wanted a bit of advice on how to go about creating a settings file
If you can imagine when you log into a router to configure it via a browser
Having created a small python file that communicates with a gpio pin I want to have the user edit a small text file using a browser to save a few settings just like an ini file really, maybe to store timings for a flashing led. I can then read in the details and assign to variables in my python code.
Is there anyway of displaying a single webpage that could save data to a text file without using a full blown web server?
If not could anyone specify a small footprint web server ?

Any advice would be gratefully received

Many thanks
Andrew

User avatar
Davespice
Forum Moderator
Forum Moderator
Posts: 1665
Joined: Fri Oct 14, 2011 8:06 pm
Location: The Netherlands
Contact: Twitter

Re: Single Webpage

Fri Oct 25, 2013 10:13 pm

You could quite easily make your python program read in a text file and parse it. Then you just need to SSH in, edit the text file, then restart your Python program.

Like this, have a file called settings.txt

Code: Select all

dave=1
spice=2
pi=3
Then in your program;

Code: Select all

#!/usr/bin/env python

file = open("settings.txt", "r")
text = file.readlines()
file.close()

settings = {}

for line in text:
        split = line.split("=")
        settings[split[0].strip()] = split[1].strip()

print settings["dave"]
print settings["spice"]
print settings["pi"]

fogmajor
Posts: 8
Joined: Fri Oct 25, 2013 8:24 pm

Re: Single Webpage

Fri Oct 25, 2013 10:40 pm

Hi There
Many thanks for the very prompt reply, I will implement your code and see how I can interact with it
I guess what I forgot to mention was that the person that may be editing the file may not have the technical skill to get to the file as you suggested and that was why I thought of a single webpage approach :)

Warm regards

Andrew

User avatar
Douglas6
Posts: 4812
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: Single Webpage

Sat Oct 26, 2013 2:37 am

Python has a built-in HTTP server class, SImpleHTTPServer (in 2.7) that might be the easiest way to do what you want. See http://docs.python.org/2/library/simplehttpserver.html and Google for some code examples.

fixitsan
Posts: 58
Joined: Sun Sep 29, 2013 4:28 pm

Re: Single Webpage

Sat Oct 26, 2013 10:28 am

Douglas6 wrote:Python has a built-in HTTP server class, SImpleHTTPServer (in 2.7) that might be the easiest way to do what you want. See http://docs.python.org/2/library/simplehttpserver.html and Google for some code examples.

I've been looking to do an identical task as the OP. The Pi will function as an RSS reader and send the RSS streams, parsed correctly, to a scrolling LED digital display to deliver a constant strem of news.

i want the user to be able to just log into a web page and add the URL of any new feed, as well as delete URL's they're no longer interested in, as well as add a few buttons to determine how often feeds should be checked, plus a few other basic controls.


I've lookedd at *a lot* of servers and frameworks and have just returned to using BaseHTTPServer and I seem to be getting going quickly. This resource has been very helpful
http://fragments.turtlemeat.com/pythonwebserver.php

fogmajor
Posts: 8
Joined: Fri Oct 25, 2013 8:24 pm

Re: Single Webpage

Sat Oct 26, 2013 7:57 pm

Many thanks for the prompt replies
I will investigate all the options suggested
Many thanks for such a friendly and helpful forum

Regards

Andrew

Return to “Beginners”