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": +, "Videocdnstatus": Ten, "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;
Python exports data from MongoDB data