两个简单的python文件,实现删除本地文件夹和mongodb数据库的内容

删除本地文件夹:

import os , string , datetime ;
str = '/home/aaa/tmp/tomcat/';
b = (datetime.datetime.now()).second + 5;
while 1 :
    a = datetime.datetime.now();
    if a.second == b :
    files = os.listdir(str);
        for file in files :
            os.remove(str+file);
        b = (a + datetime.timedelta(seconds=5)).second;

删除mongodb数据库:

import os , string , datetime , pymongo;

conn = pymongo.Connection("127.0.0.1",27017);
db = conn.nn;
coll = db.nn_res;
b = (datetime.datetime.now()).second + 5;
while 1:
    a = datetime.datetime.now();
    if a.second == b :
        curr = coll.find().sort("update_time",1).limit(1);
        for tmp in curr :    
            coll.remove(tmp);
        b = (a + datetime.timedelta(seconds=5)).second;

 

posted on 2013-11-07 14:54  Raining Days  阅读(417)  评论(0)    收藏  举报

导航