def get(self): unfixed_station_id_list = [data.station_id for data in database.EmailRecord.all().filter("latest_email", True).run()] self.response.out.write("<h4>There are %d unfixed stations.</h4>" % len(unfixed_station_id_list)) result = urlfetch.fetch(self.__class__.url) decoded = json.loads(result.content) info_list = [] for station_id in unfixed_station_id_list: station_info = [data for data in decoded if data['station_id'] == station_id] data_list=[] data_list.append(station_id) data_list.append(station_info[0]["station_name"]) data_list.append(station_info[0]["vendor_name"]) data_list.append(station_info[0]["standard_date_time"]) info_list.append(data_list) info_list = sorted(info_list, key= lambda x: datetime.datetime.strptime(x[3],"%Y-%m-%d %H:%M:%S"),reverse=True) html = MonitorHelper.buildUnfixedEmailContent(self,info_list) subject = "Unfixed Station Daily Report" MonitorHelper.emailInfo([self.__class__.email_address,"*****@*****.**"], self, subject, html)
def getInfo(self,result): '''get fawn station information''' decoded = MonitorHelper.parseJson(self,result) logging.info("Getting fawn time...") self.response.out.write("Getting fawn time...<br />") #fawn time alert_time = datetime.datetime.strptime(decoded['fawnTime'][:-4],'%A %B %d, %Y %I:%M %p') season = str(decoded['fawnTime'][-3:]) fawnData=[] self.response.out.write("fawnTime: " + str(alert_time) + " " + season) #build fawn station time list for data in decoded['stnsWxData']: self.response.out.write("<br />") fawnStn_time = datetime.datetime.strptime(data['dateTimes'][:-4],'%m/%d/%Y %I:%M %p') data_list = [] data_list.append(data['stnID']) if data['dateTimes'][-3:] =='CST' or data['dateTimes'][-3:] =='CDT': data_list.append(fawnStn_time + self.__class__.fawnStn_time_delta) self.response.out.write(str(data['stnID']) +": "+ \ str(fawnStn_time + self.__class__.fawnStn_time_delta) + " " + season) else: data_list.append(fawnStn_time) self.response.out.write(str(data['stnID']) +": "+str(fawnStn_time) + " " + season) data_list.append(data['stnName']) fawnData.append(data_list) logging.info("Getting stnID...") self.response.out.write("<br />Getting fawn stnID...<br />") #build no update list no_update_list = [data for data in fawnData if alert_time - data[1] > self.__class__.no_update_time_delta] logging.info("Getting no update stnID...") self.response.out.write(len(no_update_list)) self.response.out.write("<br />Getting no update stnID...<br />") #MonitorHelper.pushNotification(self,[]) #report no update stations if len(no_update_list) != 0: logging.info("number of no update stn ID is: %d", len(no_update_list)) missingInformation =""" number of no update stn ID is %d<br /> """ % len(no_update_list) self.response.out.write(missingInformation) subject = "FAWN ALERT NO UPDATE @ " + str(alert_time) #build email content html = MonitorHelper.buildEmailContent(self,no_update_list,season) self.response.out.write(html) #query last record in the database q = db.GqlQuery("SELECT * FROM Record \ WHERE error_code = '200'\ ORDER BY record_time DESC") queryResult = q.get() message = ",".join([data[0] for data in no_update_list]) message_time = ",".join([str(data[1]) for data in no_update_list]) self.response.out.write("Check last record in the database<br/>") if queryResult is None or message_time not in queryResult.error_time or message not in queryResult.error_details : record = database.Record(error_code = str(result.status_code),error_details = message) MonitorHelper.updateRecord(self, record, alert_time,message_time) MonitorHelper.emailInfo(self.__class__.emailList,self,subject,html) MonitorHelper.pushNotification(self,no_update_list) else: MonitorHelper.allGoodInfo(self)