39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
|
|
'''
|
||
|
|
Created on Mar 3, 2014
|
||
|
|
|
||
|
|
@author: mikewells
|
||
|
|
'''
|
||
|
|
from pymongo import MongoClient
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
client = MongoClient()
|
||
|
|
client = MongoClient('localhost', 27017)
|
||
|
|
db = client.ionu
|
||
|
|
collection = db.van
|
||
|
|
defaultVan = collection.find_one({"name": "DEFAULT VAN"})
|
||
|
|
print "What would you like the name of the new VAN to be?" ,
|
||
|
|
|
||
|
|
#Set the name of the van
|
||
|
|
name = raw_input()
|
||
|
|
defaultVan['name'] = name
|
||
|
|
|
||
|
|
#Keep increasing the _id until there is a valid unique ID.
|
||
|
|
#This is not a good method when we have a shit ton of vans!
|
||
|
|
#But I don't think we will have a ton near term
|
||
|
|
urn = int(defaultVan['_id'].split(':')[2], 16)
|
||
|
|
unique = False
|
||
|
|
while not unique:
|
||
|
|
unique = True
|
||
|
|
urn = urn + 1
|
||
|
|
for van in collection.find():
|
||
|
|
if int(van['_id'].split(':')[2], 16) == urn:
|
||
|
|
unique = False
|
||
|
|
break
|
||
|
|
urn = str(hex(urn).split('x')[1]).zfill(6)
|
||
|
|
defaultVan['_id'] = "urn:ionu:" + urn + ":::"
|
||
|
|
|
||
|
|
post_id = collection.insert(defaultVan)
|
||
|
|
print "inserted " , post_id
|
||
|
|
|
||
|
|
|
||
|
|
pass
|