Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

图片md5值计算并更新mongodb数据库记录

  • Loading branch information...
commit dab604c8e2458154d760cdbaf7a264f8a3ca1333 1 parent d08ee3a
@zhaodj authored
Showing with 26 additions and 0 deletions.
  1. +26 −0 python/md5sum.py
View
26 python/md5sum.py
@@ -0,0 +1,26 @@
+#coding=utf-8
+import os,sys,hashlib
+from pymongo import Connection
+
+def md5sum(filepath):
+ f=open(filepath,'rb')
+ m=hashlib.md5()
+ while True:
+ data=f.read(8192)
+ if not data:
+ break
+ m.update(data)
+ f.close()
+ return m.hexdigest()
+
+def upddb(imgroot):
+ con=Connection()
+ db=con.miidooo
+ for img in db.userImages.find({'type':0,'hashcode':{'$exists':0}}):
+ filepath=imgroot+img['path']
+ print(filepath)
+ if os.path.isfile(filepath):
+ db.userImages.update({'_id':img['_id']},{'$set':{'hashcode':md5sum(filepath)}})
+
+if __name__=='__main__':
+ upddb(unicode(sys.argv[1],'utf-8'))
Please sign in to comment.
Something went wrong with that request. Please try again.