Open lbp0200 opened 8 years ago
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import bsddb
import json
import time
from pymongo import MongoClient
client = MongoClient()
mongodb = client.test
mongodb.bdb.drop()
db = bsddb.btopen('/home/lbp/tmp/20160317_day.bdb', 'c')
index = 0
dlist = []
startTime = time.time()
while 1:
try:
f = db.next()
except :
mongodb.bdb.insert_many(dlist)
break
else:
data = {'date': '20160317', 'uri': f[0]}
data.update(json.loads(f[1]))
dlist.append(data)
index = index + 1
if index >= 10000:
tTime = time.time()
mongodb.bdb.insert_many(dlist)
print("--- %s seconds ---" % (time.time() - tTime))
dlist = []
index = 0
print mongodb.bdb.count()
# print result
print("--- %s seconds ---" % (time.time() - startTime))