-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvtimport.py
More file actions
59 lines (49 loc) · 1.68 KB
/
Copy pathvtimport.py
File metadata and controls
59 lines (49 loc) · 1.68 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/python
#VT property transfer XML loader git test
from pymongo import MongoClient
from lxml import etree
import glob
class VtMongoParser:
def __init__(self):
self.cl = MongoClient()
self.coll = self.cl["proptrans"]["collectionname"]
self.coll.remove()
def xmlToDict(self, xmlElement):
elementDict={}
if len(xmlElement.getchildren()) > 0:
elementDict[xmlElement.tag]={}
for c in xmlElement.getchildren():
if c.tag == "sellerList" or c.tag == "buyerList":
elementDict[xmlElement.tag][c.tag]=[]
for t in c.getchildren():
listDict=self.xmlToDict(t)
elementDict[xmlElement.tag][c.tag].append(listDict)
else:
elementDict[xmlElement.tag][c.tag]=self.xmlToDict(c)
else:
return xmlElement.text
return elementDict
def loadMongo(self, filepath):
print "Digesting XML file: "+str(filepath)
xml=etree.parse(filepath)
i = 0
for event in xml.getroot().xpath("//formData"):
i+=1
proptransrecord = self.xmlToDict(event)
self.coll.insert(proptransrecord)
parser = VtMongoParser()
for filename in glob.glob("/Users/tcarr/proptrans/PT20141*.xml"):
parser.loadMongo(filename)
#exit(1)
#results=parser.coll.find({"formData.sellerList.seller.lastName": "CARR"})
results=parser.coll.find({"$and":
[{"formData.sellerList.seller.lastName": "CARR"},
{"formData.sellerList.seller.firstName": "JUDY"}]})
#results=parser.coll.collectionname.find({"lastName": "SMITH"})
print results.count()
#for item in results:
# print str(item)
#db.collectionname.aggregate([
# { "$project": { "name": { "$concat" : [ "formData.sellerList.seller.lastName", " ", "formData.sellerList.seller.firstName" ] } } },
# { "$match" : { "name": /smith glori/i } }
#])