python

Convert Epoch time to Normal time with Python

I have a long integer time that I believe is actually epoch time. The Python methods to convert epoch time to/from “normal” time (human readable time).

Convert Epoch to Human-readable

import time 
 
# where epoch is your epoch time value
 
time.strftime("%a, %d %b %Y %H:%M:%S +0000", 
                        time.localtime(epoch))

http://www.epochconverter.com/

Setting up Python Pyjamas

I’m just playing around with the Python Pyjamas toolkit for no reason. The Pyjamas Book is slightly difficult to follow. Here are my notes.

Check out Pyjamas from Git and run bootstrap file.

$: git clone git://pyjs.org/git/pyjamas.git
$: cd pyjamas
$: python bootstrap.py 

Running bootstrap.py creates a bin directory. If you plan on playing with this a lot it may be worthwhile to link the files in bin to your environment path.

## (I have ~/bin referenced on my environment path. You might not!)
$: ln -s ../pyjamas/bin/pyjscompile ~/bin
$: ln -s ../pyjamas/bin/pyjsbuild ~/bin

Try an example

$: cd ../pyjamas/examples/helloworld
$: pyjsbuild Hello.py
= pyjamas Compiles some stuff into ./output =

Pyjamas dumps a bunch of files into an output subdirectory. Take a look at the Hello.html file that got generated.

Now you can follow the Pyjamas book.

For now: figure out how to create a UI with Pyjamas.

Next Steps: Use Pyjamas with Google App Engine.

Installing psycopg2 on Mac 10.6.4 Snow Leopard

Setting up Django for use with Postgres 8.3. Django uses psycopg2 (or psycopg depending on what you choose). To the best of my knowledge psycopg2 v2.2.2 is the most stable version of the code.

easy_install "psycopg2=2.2.2"

Then edit your settings.py file for Django.

DATABASE_ENGINE = ‘postgresql_psycopg2’

Psycopg2 Error

The easy_install for psycopg2 didn’t work immediately because easy_install could not find pg_config and caused compile process failed. To fix the problem I needed my environment to have access to Postgres 8.3 pg_config. The default MacPorts install of Postgres 8.3 drops pg_config and other key files into /opt/local/lib/postgresql83/bin/ .

To allow your easy_install environment to see pg_config, simply symbolically link it to your ~/bin directory. It does not have to be ~/bin. It could be any directory on your environment path. Just pick something easy.

# symbolic link from MacPorts install of postgres to a path on my home dir.
ln -s /opt/local/lib/postgresql83/bin/pg_config ~/bin/pg_config

I edited my .bash_profile so that the files in ~/bin is always on my environment path.

# set PATH so it includes user’s private bin if it exists
if [ -d ~/bin ] ; then
    PATH=~/bin:"${PATH}"
fi
 
if [ -f /opt/local/etc/bash_completion ]; then
    . /opt/local/etc/bash_completion
fi
Syndicate content