Guest User

Untitled

a guest
Dec 3rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import pymysql.cursors
  2. import json
  3.  
  4. connection = pymysql.connect(host='localhost',
  5. user='wikiuser',
  6. password='secret service',
  7. db='wikidb',
  8. cursorclass=pymysql.cursors.DictCursor)
  9. # range(20881, 1, -1)
  10. for i in [142]:
  11. try:
  12.  
  13. with connection.cursor() as cursor:
  14. sql = "SELECT `old_text` FROM `text` WHERE `old_id`=%s"
  15. cursor.execute(sql, (str(i),))
  16. result = cursor.fetchone()
  17. try:
  18. old_text = json.loads(result['old_text'].decode('utf8'))
  19. except:
  20. continue
  21. if 'forms' not in old_text or not old_text['forms']:
  22. continue
  23. new_forms = []
  24. new_text = old_text
  25. for form in old_text['forms']:
  26. if 'id' in form and form['id'].startswith('F'):
  27. form['id'] = old_text['id'] + '-' + form['id']
  28. new_forms.append(form)
  29. new_text['forms'] = new_forms
  30. if new_text != old_text:
  31. print(new_text['forms'], old_text['forms'])
  32. finally:
  33. connection.close()
Add Comment
Please, Sign In to add comment