zoukankan      html  css  js  c++  java
  • 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+" ")

    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;

  • 相关阅读:
    bzoj1103[POI2007]大都市meg
    bzoj1098[POI2007]办公楼biu
    bzoj1102[POI2007]山峰和山谷Grz
    POI刷题记录
    语法-指针
    dp-最长公共子序列
    如何判断素数
    C++的map用法
    stl-优先队列
    C++和Java的stack语法
  • 原文地址:https://www.cnblogs.com/adolfmc/p/7468631.html
Copyright © 2011-2022 走看看