qotnews/apiserver/migrate-whoosh-to-sqlite.py

23 lines
579 B
Python
Raw Normal View History

2020-06-25 23:41:15 +00:00
import archive
import database
import json
database.init()
archive.init()
with archive.ix.searcher() as searcher:
for docnum in searcher.document_numbers():
try:
2020-06-26 00:36:26 +00:00
if docnum > 500:
break
2020-06-25 23:41:15 +00:00
print('docnum', docnum)
res = searcher.stored_fields(docnum)
print('id', res['id'])
2020-06-26 00:36:26 +00:00
database.put_story(res['story'])
database.put_ref(res['story']['ref'], res['id'])
2020-06-25 23:41:15 +00:00
print()
2020-06-26 00:36:26 +00:00
except BaseException as e:
2020-06-25 23:41:15 +00:00
print('skipping', docnum)
2020-06-26 00:36:26 +00:00
print('reason:', e)