Shoutbox: Get the timestamp form the client's browser

Posted by Tobias 
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.
Now, this forum is in read-only mode. You find details Details hereContinue on /r/PirateBox
Shoutbox: Get the timestamp form the client's browser
July 28, 2014 06:30PM
Hi. As you know, the Raspberry Pi doesn't have a real time clock and therefore the timestamps in the chat are wrong if you didn't boot your Pi with an internet connection. To get correct timestamps, i had the idea to send them from the client's browser with the chat message. In order to do that, I added a small Javascript to the index.html that generates a POSIX timestamp and sends it with the chat message to the server. There the modified python scripts take the timestamp and generate a corresponding localized timestamp which will be displayed in the chat box.

This is what I have changed so far: [github.com]

I think the best would be to add a new variable to a configuration file which allows the user to enable/disable the use of the client's timestamps. But because I am new to Python I don't know how I can add such a variable.
Re: Shoutbox: Get the timestamp form the client's browser
July 30, 2014 05:59AM
Hi Tobias,
I just checked out the code, that looks good so far !

To make an additional environment var, you need to modify those files:

[github.com]
[github.com]

And here you can see how to access that var:
[github.com]

Thanks for your contribution!

Matthias


This is only my signature.
Re: Shoutbox: Get the timestamp form the client's browser
July 31, 2014 10:47PM
clienttimestamp =os.environ["SHOUTBOX_CLIENT_TIMESTAMP"]
in psogen.py only works when I add the variable to the env file in the directory /conf/lighttpd. I tried to change the generate_lighttpd_env() function in generate_config_files.sh so that the variable will be added to the env file, but it didn't work.

generate_lighttpd_env() {
        local GLOBAL_CHAT=$1
        local GLOBAL_DEST="$2"
	local PYTHONPATH=$3
	local SHOUTBOX_GEN_HTMLFILE=$4
	local PIRATEBOX=$5
	local SHOUTBOX_CHATFILE=$6
	local SHOUTBOX_CLIENT_TIMESTAMP=$7

        echo "Generating Environment-config for lighttpd ....."

        LIGHTTPD_ENV_BR_LINE=""
	if [ "$GLOBAL_CHAT" = "yes" ] ; then
	     LIGHTTPD_ENV_BR_LINE="   \"SHOUTBOX_BROADCAST_DESTINATIONS\" => \"$GLOBAL_DEST\" , "
	fi

	LIGHTTPD_ENV="setenv.add-environment = ( 
	   \"PYTHONPATH\"             => \"$PYTHONPATH:$PIRATEBOX/python_lib\", 
	   \"SHOUTBOX_GEN_HTMLFILE\"  => \"$SHOUTBOX_GEN_HTMLFILE\" , 
	   \"SHOUTBOX_CHATFILE\"      => \"$SHOUTBOX_CHATFILE\" , 
	   \"SHOUTBOX_CLIENT_TIMESTAMP\" => \"$SHOUTBOX_CLIENT_TIMESTAMP\" , 
	   $LIGHTTPD_ENV_BR_LINE 

        )"

       echo $LIGHTTPD_ENV > $LIGHTTPD_ENV_CONFIG
}

...

generate_lighttpd_env $GLOBAL_CHAT "$GLOBAL_DEST" $PIRATEBOX_PYTHONPATH $GEN_CHATFILE $PIRATEBOX_FOLDER  $CHATFILE $SHOUTBOX_CLIENT_TIMESTAMP

I also added
export SHOUTBOX_CLIENT_TIMESTAMP=$SHOUTBOX_CLIENT_TIMESTAMP
to the shoutbox_stuff.sh file and
SHOUTBOX_CLIENT_TIMESTAMP="no"
to the piratebox.conf file.
Re: Shoutbox: Get the timestamp form the client's browser
August 04, 2014 05:37PM
Hi Tobias,
sorry, I forgot that part.

Can you add this to your repository on github and push me a pull-request please?

Thank you very much for your work!

Matthias


This is only my signature.