Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import sys
  4. import sqlite3
  5. from uuid import uuid4
  6. conn = sqlite3.connect('places.backup.sqlite', detect_types=sqlite3.PARSE_COLNAMES)
  7. conn.row_factory = sqlite3.Row
  8. cur = conn.cursor()
  9.  
  10. drop_tables = [
  11. 'moz_historyvisits',
  12. 'moz_inputhistory',
  13. 'moz_bookmarks',
  14. 'moz_bookmarks_roots',
  15. 'moz_keywords',
  16. 'moz_favicons',
  17. 'moz_annos',
  18. 'moz_anno_attributes',
  19. 'moz_items_annos',
  20. 'moz_hosts']
  21.  
  22. # remove extraneous tables
  23. for t in drop_tables:
  24. try:
  25. cur.execute('DROP TABLE {}'.format(t))
  26. conn.commit()
  27. print('dropped:\t{}'.format(t))
  28. except Exception as e:
  29. print('warning:\t{}'.format(e.message))
  30.  
  31. host_map = {}
  32. rows = cur.execute('SELECT DISTINCT(rev_host) FROM moz_places').fetchall()
  33. for row in rows:
  34. rev_host = row['rev_host']
  35. host_map[rev_host] = str(uuid4())
  36.  
  37. total_count = cur.execute('SELECT COUNT(*) as total FROM moz_places').fetchone()['total']
  38. count = 0
  39.  
  40. for rev_host, uid in host_map.iteritems():
  41. rows = cur.execute('SELECT id, guid FROM moz_places WHERE rev_host = ? ORDER BY id', [rev_host]).fetchall()
  42. for row in rows:
  43. cur.execute('UPDATE moz_places SET rev_host = ?, url = ?, title = ? WHERE id = ?', [host_map[rev_host], row['guid'], row['guid'], row['id']])
  44. count += 1
  45. print('anonymizing:\t{: 9d}/{} records\r'.format(count, total_count), end='')
  46.  
  47. rows = cur.execute('SELECT id, guid FROM moz_places WHERE rev_host is NULL').fetchall()
  48. for row in rows:
  49. cur.execute('UPDATE moz_places SET url = ? WHERE id = ?', [row['guid'], row['id']])
  50. count += 1
  51. print('anonymizing:\t{: 9d}/{} records\r'.format(count, total_count), end='')
  52.  
  53. print('\ncommitting')
  54. conn.commit()
  55. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement