python 导出mongoDB数据中的数据
import pymongo,urllib
import sys
import time
import datetime
reload(sys)
sys.setdefaultencoding('utf8')
from pymongo.connection import Connection
from datetime import timedelta
import os
connection=pymongo.Connection('127.0.0.1',27017)
db = connection.upload
db.authenticate("username","passowd")
format="%Y-%m-%d %H:%M:%S"
fileName="dstUrl"
datefmt="%m%d"
now = datetime.datetime.now().replace(day=1,hour=0,minute=0,second=0)
aDay = timedelta(days =-1)
endDate=now+aDay
startDate=endDate.replace(day=1)
endDateStr=endDate.strftime(format)
startDateStr=startDate.strftime(format)
startTime=int(time.mktime(time.strptime(startDateStr, '%Y-%m-%d %H:%M:%S'))*1000)
endTime=int(time.mktime(time.strptime(endDateStr, '%Y-%m-%d %H:%M:%S'))*1000)
#f=open(fileName, "w")
fileName=fileName+"("+startDate.strftime(datefmt)+"-"+endDate.strftime(datefmt)+").txt"
def findList(startTime,endTime):
print "startTime"+startDateStr+" endTime"+endDateStr
query={"completeTime":{"$gte":startTime,"$lt":endTime},"status":30,"videoCDNStatus":10,"checksumStatus":10,"mmsStatus":1}
encodeCursor=db.video_encode.find(query)
historyCursor=db.video_encode_history.find(query)
taskIterator(encodeCursor)
taskIterator(historyCursor)
def taskIterator(cusor):
for encode in cusor:
mid=encode["mid"]
encodeId=encode["encodeId"]
vtype=encode["vtype"]
dstUrl=encode["dstUrl"]
checksumPath=encode["checksumPtah"]
f.write(str(mid)+","+str(encodeId)+","+vtype+","+dstUrl+","+checksumPath+"\n")
print "start run to export dst url to file %s",fileName
if(os.path.isfile(fileName)):
print "file %s is exsis ,not create file",fileName
else:
f=open(fileName, "w")
findList(startTime,endTime)
f.close;
相关文章
- pycharm 安装包失败_python安装库为什么不成功
- Python爬取热搜数据之炫酷可视化[通俗易懂]
- python jieba库_Python jieba库的使用说明「建议收藏」
- Python入门系列(五)一篇搞懂python语句
- python写helloworld代码_helloworld代码怎么写?
- 【说站】python help()获取函数信息
- pycharm怎么编译代码_python编程
- Python 反转字符串_python输出字符串
- Python绘制旭日图_python绘制散点图
- 初学者java编程软件_编写python的软件
- 基于Python的OpenCV有关像素的操作
- 【Python】字符串 ④ ( Python 浮点数精度控制 | 控制数字的宽度和精度 )
- python-Python与MongoDB数据库-MongoDB数据库的基本知识
- python-Python与MongoDB数据库-使用Python执行MongoDB查询(一)
- mongoDB数据库备份恢复 之 mongodb 4.2.8备份恢复与导出导入
- MongoDB存储视频:实现高效灵活的视频存储方式(mongodb存储视频)
- 如何解决MongoDB空间不足问题(mongodb空间不足)
- MongoDB配置安全身份认证机制(mongodb身份认证)
- MongoDB:优秀的数据库解决方案(mongodb的使用场景)
- 如何正确卸载Mac上的MongoDB(mac卸载mongodb)
- MongoDB数据的导入导出实践(mongodb导入导出)
- 快速实现MongoDB库导出:轻松备份数据(mongodb导出库)
- MongoDB实现字段复制的简单方法(mongodb复制字段)
- MongoDB的篡改锁保护机制(mongodb的锁)
- MongoDB数据库中添加字段的操作(mongodb添加字段)
- Exploring the Architecture of MongoDB: A Visual Guide(mongodb架构图)
- 利用mongodump工具导出MongoDB数据的快速指南(导出mongodb数据)
- MongoDB:利用多核处理器提升性能(mongodb 多核)
- 及优缺点MongoDB分片技术:原理与优缺点分析(mongodb分片原理)
- Linux下从系统卸载Python(linux下卸载python)
- python模块restful使用方法实例