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;