Working python script for database querying.