#!/usr/bin/env python
#--*-- coding:UTF-8 --*--
import psycopg2

def getdsn(db = None, user = None, passwd = None, host = None):
	if user == None:
		import os, pwd
		user = pwd.getpwuid(os.getuid())[0]
	if db == None:
		db=user
	dsn='dbname=%s user=%s'%(db,user)
	if passwd != None:
		dsn += ' password=' + passwd
	if host != None:
		dsn += ' host=' + host
	return dsn

dsn=getdsn('python_db','javier',' ','localhost')
print "Conexion a %s"%dsn
dbh=psycopg2.connect(dsn)
print "conexión conseguida."
cur=dbh.cursor()
cur.execute("CREATE TABLE ediciones_eni (mon_num integer UNIQUE, ma_chaine varchar(30))")
cur.execute("INSERT INTO ediciones_eni VALUES (0)")
dbh.commit()
dbh.close()
