Skip to content

Commit a74974e

Browse files
author
tuntun
committed
Python3下载MongoDB上的文件
1 parent 91564cd commit a74974e

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

testmongo.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
21
from pymongo import MongoClient
3-
import datetime
2+
import gridfs
3+
import time
4+
import re
5+
import os
6+
import sys
47

5-
client = MongoClient('mongodb://tanteng:123456@localhost:27017/')
8+
client = MongoClient('mongodb://192.168.1.22:27017/excel')
69
db = client.js_send_excel
10+
fs = gridfs.GridFS(db)
11+
files = fs.find()
12+
13+
time_start = time.clock()
14+
print('总数:', files.count())
15+
16+
for ffle in files:
17+
filename = ffle.filename
18+
m = re.match(r'发货订单', filename)
719

8-
post = {"author": "Xiaofeng", "text": "My first blog post!",
9-
"tags": ["mongodb", "python", "pymongo"],}
20+
if m and filename.find('.xls') > 0 and not os.path.isfile('./excel/' + filename):
21+
with open('./excel/' + filename, 'wb') as f1:
22+
f1.write(ffle.read())
1023

11-
posts = db.posts
12-
post_id = posts.insert_one(post).inserted_id
13-
print(post_id)
24+
print('执行时间{0}秒'.format(time.clock() - time_start))

0 commit comments

Comments
 (0)