python????????MongoDB?????
???????????? ???????[ 2014/4/2 9:20:46 ] ????????????? python
????????????????MongoDB????JSON??BSON ?????????? ???????????????????? ?y??????????????????п???????????????????????????????????????д?????????????£?
#!/usr/bin/env python
#encoding:utf-8
###################################
# function: analysis the log in the 'die' to JSON ?? and
#output the data to the MongoDB.
# data: 2014/3/31
#History: 1.0
###################################
import os
import pymongo
def connect_mongodb():
servers="mongodb://localhost:27017"
conn = pymongo.Connection(servers)
print conn.database_names()
db = conn.my_mongodb #?????
return db
def str_process(string??db):
d={}
if string == '
':
return
string2=str(string)
print '-----'+string
string2=string2.split(' ')
print '---------------'
print string2
for i in string2:
print i
print '------------'
string2[3].split('
')
d['projectcode']=string2[0]
d['pagename']=string2[1]
d['pageview']=string2[2]
d['bytes']=string2[3][:-1]
db.user.insert(d)
def file_process(source_file??db):
string2=''
f=open(source_file??'r')
print 'file name :'+source_file
while True:
string2=f.readline()
if string2 == '':
break
string2=str_process(string2??db)
print string2
def get_dir_list(dir): #input the dir ??will output the all filename
dat0=[]
for i in os.listdir(dir):
dat0.append(i)
return dat0
def all_file_process():
dir_file_name=''
dir_list=[]
dir_file_name=raw_input('please input the dir name:')
dir_list=get_dir_list(dir_file_name)
print dir_list
db=connect_mongodb()
for i in dir_list:
if str(i) != 'log_file_process.py':
file_process(str(i)??db)
all_file_process()
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11