Created
December 1, 2017 11:38
-
-
Save Ladsgroup/d26bc4918e95bc4f7ec2248d7027acfc to your computer and use it in GitHub Desktop.
database cleaner
This file contains hidden or 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 pymysql.cursors | |
import json | |
connection = pymysql.connect(host='localhost', | |
user='wikiuser', | |
password='secret service', | |
db='wikidb', | |
cursorclass=pymysql.cursors.DictCursor) | |
# range(20881, 1, -1) | |
for i in [142]: | |
try: | |
with connection.cursor() as cursor: | |
sql = "SELECT `old_text` FROM `text` WHERE `old_id`=%s" | |
cursor.execute(sql, (str(i),)) | |
result = cursor.fetchone() | |
try: | |
old_text = json.loads(result['old_text'].decode('utf8')) | |
except: | |
continue | |
if 'forms' not in old_text or not old_text['forms']: | |
continue | |
new_forms = [] | |
new_text = old_text | |
for form in old_text['forms']: | |
if 'id' in form and form['id'].startswith('F'): | |
form['id'] = old_text['id'] + '-' + form['id'] | |
new_forms.append(form) | |
new_text['forms'] = new_forms | |
if new_text != old_text: | |
print(new_text['forms'], old_text['forms']) | |
finally: | |
connection.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment