Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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()
Add Comment
Please, Sign In to add comment