forked from ganoti/prices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmltomongo.py
49 lines (39 loc) · 1.33 KB
/
xmltomongo.py
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
# -*- coding: utf-8 -*-
"""============================================================================
Name:
@author: Dean Langsam
@Created: Fri Jun 05 12:33:09 2015
============================================================================"""
import xmltodict as xtd
import pymongo as mng
import os
def dict_to_db():
pass
#Server IP: 130.211.170.156
mongo_con = mng.MongoClient(host = 'localhost',
port = 27017)
db=mongo_con.eifozol
collection=db.test
print os.getcwd()
rootdir = "./xml/daily"
for subdir, dirs, files in os.walk(rootdir):
# print subdir
# print dirs
for xml_file in files:
if xml_file.endswith('.xml'):
names = subdir.split('\\')
date = 'date{}'.format(names[1])
collection s= db[date]
chain = names[2]
branch = names[3]
content_type = xml_file[0:5]
xml_path = "{}\\{}".format(subdir,xml_file)
with open (xml_path) as f:
prices_dict = xtd.parse(f)
mongo_dict = dict(date = date,
chain = chain,
branch = branch,
content_type = content_type,
content = prices_dict)
collection.insert(mongo_dict)
print ('file OK')