This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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')) |