-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport.py
More file actions
32 lines (26 loc) · 728 Bytes
/
import.py
File metadata and controls
32 lines (26 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from datetime import datetime
from sqlite3 import connect, Row
from pyelasticsearch import ElasticSearch
es = ElasticSearch('http://localhost:9200/')
# es.search('name:joe')
conn = connect('/Users/xq/Workspace/my-trac-proj/db/trac.db')
conn.row_factory = Row
def index_wiki(r):
doc = {}
doc['name'] = r['name']
doc['comment'] = r['comment']
doc['author'] = r['author']
doc['text'] = r['text']
doc['version'] = r['version']
doc['time'] = datetime.fromtimestamp(r['time'] / 1000000)
doc['ipnr'] = r['ipnr']
es.index('trac', 'wiki', doc, doc['name'])
c = conn.cursor()
c.execute('select * from wiki')
rows = c.fetchmany(50)
while rows:
for r in rows:
index_wiki(r)
rows = c.fetchmany(50)
c.close()
conn.close()