-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript_insert.py
More file actions
48 lines (33 loc) · 818 Bytes
/
script_insert.py
File metadata and controls
48 lines (33 loc) · 818 Bytes
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
#auther:Feixue Zhang
#usage: ./**.py data_file db_collection_name
import os,sys
from pymongodb import mongoDB
header=['script_name','loc','purpose','input','output','usage']
db=mongoDB('datashare')
def readData():
f = file(sys.argv[1])
# print sys.argv[1]
allData=[]
while True:
item={}
line=f.readline()
if len(line) == 0:
break
# print line
terms=line.split(';')
for i in range(0,len(terms)):
item[header[i]]=terms[i]
# print item
allData.append(item)
# print allData
return allData
def insertDB(collection,alldata):
for i in range(0,len(alldata)):
db.insert(collection,alldata[i])
#data={'name':'zfx','age':'24'}
#print db.insert('log',data)
#print db.findOne('log',{'name':'zfx'})
file_d=readData()
insertDB(sys.argv[2],file_d)
all=db.findAll(sys.argv[2])
print all