if(key not in data): data[key] = StatElement(ele["user_key"], long(ele["group_id"]), ele["time"]) data[key].add(ele) else: print "error" path = "/data/xce/Ad/log/AdLogS0/stat_log" adapter = AdQualityAdapter(0) last_update_time = "-1" #last_update_time = "2010-12-10 13:37:00" try: last_update_time = adapter.GetLastUpdateTime() except: print "adapter.Get last update time error" traceback.print_exc() midmail.send("quality adapter get last update time error", "*****@*****.**") sys.exit(0) print last_update_time if re.match('\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d', last_update_time) is None: print "last update time format error" sys.exit(0) last_update_time = time.strptime(last_update_time, "%Y-%m-%d %H:%M:%S") begin_minute = time.localtime(time.mktime(last_update_time) + 60) # 从上次更新时间的下一分开始 end_minute = time.localtime(time.time() - 60) # 结束时间为当前时间的前一分钟 if time.mktime(end_minute) - time.mktime(begin_minute) > 60 * 60: #检查上次更新时间是否过长,一小时前 errlog = "last update time is %s, which is one hour before" %last_update_time midmail.send(errlog, "*****@*****.**") sys.exit(0)
else: print "error" logger.info("Enter ad_quality_hourly.py") path = "/data/xce/Ad/log/AdLogS0/stat" #ans = ["/data/xce/Ad/log/AdLogS0/stat/stat.2010-12-08-16"]#util.getLastHourLogs(path) #ans = ["stat.2010-12-06-11"]#util.getLastHourLogs(path) ans = util.getLastHourLogs(path) for filename in ans: print filename for filename in ans: file = open(filename, "r") time = filename.split(".")[1] tlist = time.split("-") for line in file: if(len(line) <= 1): continue mp = util.makeDictByLog(line) mp["db_time"] = ("%s-%s-%s %s:00:00") %(tlist[0], tlist[1], tlist[2], tlist[3]) insert(mp) file.close() for ele in data: data[ele].insertIntoDb() logger.info("%s is done" %filename) middb.closeDbConnection() if(senderr == 1): midmail.send(senderr_msg, "*****@*****.**") logger.info("Exit ad_quality_hourly.py")
logger.info("Enter ad_quality_hourly.py") path = "/data/xce/Ad/log/AdLogS0/stat" #ans = ["/data/xce/Ad/log/AdLogS0/stat/stat.2010-12-08-16"]#util.getLastHourLogs(path) #ans = ["stat.2010-12-06-11"]#util.getLastHourLogs(path) ans = util.getLastHourLogs(path) for filename in ans: print filename for filename in ans: file = open(filename, "r") time = filename.split(".")[1] tlist = time.split("-") for line in file: if (len(line) <= 1): continue mp = util.makeDictByLog(line) mp["db_time"] = ("%s-%s-%s %s:00:00") % (tlist[0], tlist[1], tlist[2], tlist[3]) insert(mp) file.close() for ele in data: data[ele].insertIntoDb() logger.info("%s is done" % filename) middb.closeDbConnection() if (senderr == 1): midmail.send(senderr_msg, "*****@*****.**") logger.info("Exit ad_quality_hourly.py")
ele["time"]) data[key].add(ele) else: print "error" path = "/data/xce/Ad/log/AdLogS0/stat_log" adapter = AdQualityAdapter(0) last_update_time = "-1" #last_update_time = "2010-12-10 13:37:00" try: last_update_time = adapter.GetLastUpdateTime() except: print "adapter.Get last update time error" traceback.print_exc() midmail.send("quality adapter get last update time error", "*****@*****.**") sys.exit(0) print last_update_time if re.match('\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d', last_update_time) is None: print "last update time format error" sys.exit(0) last_update_time = time.strptime(last_update_time, "%Y-%m-%d %H:%M:%S") begin_minute = time.localtime(time.mktime(last_update_time) + 60) # 从上次更新时间的下一分开始 end_minute = time.localtime(time.time() - 60) # 结束时间为当前时间的前一分钟 if time.mktime(end_minute) - time.mktime( begin_minute) > 60 * 60: #检查上次更新时间是否过长,一小时前 errlog = "last update time is %s, which is one hour before" % last_update_time