Skip to content

Instantly share code, notes, and snippets.

@vkolev
Created March 1, 2010 23:12
Show Gist options
  • Save vkolev/318919 to your computer and use it in GitHub Desktop.
Save vkolev/318919 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#
# formatter.py
#
# Copyright 2010 Vladimir Kolev <admin@vladimirkolev.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import codecs
import MySQLdb
from pysqlite2 import dbapi2 as sqlite
def main():
try:
conn = MySQLdb.connect(host = 'localhost', user = 'root', passwd = '*****', db = 'women')
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit(1)
try:
c = conn.cursor()
ct = sqlite.connect('women.db')
cursor = ct.cursor()
for i in range(1, 150):
c.execute("""SELECT lafs FROM texts WHERE id = %i""" % i)
row = c.fetchone()
print row
cursor.execute("INSERT INTO women(womenfact) VALUES('%s')" % (row[0].decode('utf-8')))
ct.commit()
cursor.close()
c.close()
except MySQLdb.Error, e:
print "Error %d: %s" % (e.args[0], e.args[1])
sys.exit(1)
if __name__ == '__main__': main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment