cablegates/pandora/load_from_mongodb.py
2011-09-05 15:03:14 +02:00

22 lines
619 B
Python

from pymongo import Connection
connection = Connection()
db = connection.cablegates
cables = db.cables
import item.models
ids = [c['refid'] for c in cables.find(keys=['refid'])]
for id in ids:
i, created = item.models.Item.objects.get_or_create(itemId=id)
if not i.data:
cable = cables.find_one({'refid': id})
i.data = cable
del i.data['_id']
del i.data['id']
i.data['created_day'] = i.data['created'].strftime('%Y-%m-%d')
i.data['released_day'] = i.data['released'].strftime('%Y-%m-%d')
print i.data['refid']
i.public = True
i.save()