Reputation: 219
At the moment I am planning a project with the RaspberryPi. Therefore I plan to write a script in Python that runs in the background and reacts to user input (buttons, rotary knob, etc.). Additional to the Python script I have a webinterface with PHP under it. The goal is to lat the user change settings through the webinterface and pass the changed variables (e.g. a Twitter username) to the Python script so it can update its variables.
Unfortunatelly I have no idea how to pass data to the running Python script. Do you have any ideas?
Upvotes: 2
Views: 985
Reputation: 114038
store modifiable settigns in a json file
settings.json
{"twitter_user": "bob"}
before doing something load your json settings
myscript.py
import json
def do_something():
settings = json.load(open("settings.json"))
print settings["twitter_user"]
update your settings.json via php as needed
myscript.php
function change_twitter_user($uname){
$settings = json_decode(file_get_contents($file));
$settings["twitter_user"] = $uname
file_put_contents("/path/to/settings.json",json_encode($settings ));
}
thats probably the easiest way to do it
(although you do know that python has some very nice web stuff also right?)
Upvotes: 2