code

Released MonitorES 1.0b

Hello All,

I am pleased to announce that new version of MonitorES ( Monitor Energy Saver) 1.0b is released with lot of cool features.  Please download the latest from http://code.google.com/p/monitores

Features:

  • Support for Windows 7 ( including mute)
  • Custom Hotkey’s
  • Disable Screensaver.
  • and more…

Cheers,

Umakanth

Connect Oracle DB from Python

Simple steps to connect to oracle database from windows operating system.

Requirements:

To connect to oracle we need either oracle client installed on your local machine or instant client from oracle ( recommended , if you don’t have oracle client)

Get the proper version of Python and cxOracle versions ( I’ve used Python 2.6.4 with cxOracle 5.0.2 and Oracle 10g ) . If you have installed everything , get the oracle instant client and extract to your local folders.

Say example , I’ve extracted it to c:\insOracle\

Now, We should create or update ORACLE_HOME and PATH variable for instant client.

from console ,

 
set ORACLE_HOME = C:\insOracle\
 
PATH = %PATH%;C:\insOracle\

Or you can add it to your system path using windows path editor.

That’s it. Now we can connect to oracle from python. Make sure that you don’t use “;” at the end of your queries from python.

Export MySQL database in XML format

This small python program can export mysql database in a xml format

import MySQLdb
 
hostName="hostnamehere"
userName="usernamehere"
passWd="passwordhere"
dbName="dbnamehere"
 
print "Started...."
 
#open file
file = open("out.xml", 'w')
 
file.write("");
file.write("\n\t<" + dbName + ">");
 
print "Connecting to " , hostName , "...";
conn=MySQLdb.connect(host=hostName,user=userName,passwd=passWd,db=dbName)
cursor = conn.cursor ()
 
table_list = []
 
#get server version
cursor.execute ("SELECT VERSION()")
row = cursor.fetchone ()
server_version = row[0];
print "Detected MySQL version ", server_version
 
# get all the tables
print "Getting tables...";
cursor.execute("show tables");
for row in cursor:
table_list.append(row[0])
 
# lets get all the tables values
for table in table_list:
file.write("\n\t<" + table + ">");
print "Processing ", table , " ..."
sql_desc = "desc " + table;
cursor.execute(sql_desc);
type_list = []
for row in cursor:
type_list.append(row[0])
# now data
sql_table_rows = "select * from " + table;
cursor.execute(sql_table_rows);
for row in cursor:
for i in range(len(type_list)):
file.write("\n\t\t<" + type_list[i] + ">" + "%s" %row[i] + "")
file.write("\n\t")
 
file.write("\n\t");
file.close();
print "XML file(out.xml) successfully written"