Skip to content

Instantly share code, notes, and snippets.

@andilabs
Created February 20, 2014 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andilabs/9116758 to your computer and use it in GitHub Desktop.
Save andilabs/9116758 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import MySQLdb
dir_texts = 'raw_text_gumtree_opis'
def write_to_file(with_name, write_this):
with_name = dir_texts +"/"+ str(with_name)
with open(with_name, "w") as F:
F.write(write_this)
db = MySQLdb.connect(host="mysql.superhost.pl", # your host, usually localhost
user="FOO", # your username
passwd="BAR", # your password
db="FOOBAR",# name of the data base
charset = "utf8",
use_unicode = True)
# you must create a Cursor object. It will let
# you execute all the query you need
cur = db.cursor()
# Use all the SQL you like
cur.execute("select id, opis from Mieszkanie")
for row in cur.fetchall() :
write_to_file(row[0],row[1].encode('utf8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment