Last active
October 2, 2015 13:58
-
-
Save altmind/2253719 to your computer and use it in GitHub Desktop.
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
import re | |
import sys | |
import time | |
__author__ = 'altmind' | |
import MySQLdb | |
conn = MySQLdb.connect(host="localhost", | |
user="root", | |
passwd="", | |
db="test") | |
def processReplacement(replacement, row, cursor): | |
cursor.execute("UPDATE PROF SET INFO_PROCESSED=%s, PROCESSED=1 WHERE ID=%s",(replacement, row["ID"])) | |
def repl(m): | |
return "?" | |
def processQuery(subject): | |
subject = re.sub('"', "'", subject) | |
subject = re.sub(r"\s+", " ", subject) | |
subject = re.sub(r"(?i)(\s*in\s*)\([^)]*(?:\)|$)|(is)\s*(?:not)?\s*null|(?:_[a-z0-9]+)?'([^'\\]|\\.)*?'|(?:[^a-z_0-9])\d+", repl, subject) | |
return re.sub(r"\?{2,}", "?", subject) | |
while(True): | |
cursor = conn.cursor(MySQLdb.cursors.DictCursor) | |
cursor.execute("SELECT * from PROF WHERE PROCESSED=0") | |
result_set = cursor.fetchall() | |
for row in result_set: | |
replacement = processQuery(row["INFO"]) | |
processReplacement(replacement, row, cursor) | |
print row["ID"] | |
sys.stdout.flush() | |
cursor.close() | |
conn.commit() | |
time.sleep(1) | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment