def report_overview(starttime, endtime, data, reportfile, reporttitle, scenario): """Create the report file, this part is application specific.""" # Note: I use ZPT. Of cause if you would prefere something else # you can use it here pt_loader = TemplateLoader(here('./templates'), auto_reload=True) template = pt_loader.load('response_times.pt') result = template(starttime=starttime, endtime=endtime, data=data, reporttitle=reporttitle, scenario=scenario).encode( 'ISO-8859-1') fo = open(reportfile, 'w') fo.write(result) fo.close()
class GatewayMiddleware(object): def __init__(self, app, global_conf, password, cookie_name, cookie_value, domain, lifetime=DEFAULT_COOKIE_LIFETIME, default_message=''): self.app = app self.password = password self.cookie_name = cookie_name self.cookie_value = cookie_value self.domain = domain self.lifetime = lifetime self.default_message = default_message self.loader = TemplateLoader(os.path.dirname(__file__)) def __call__(self, environ, start_response): request = Request(environ) password = request.params.get('password', None) if request.cookies.get(self.cookie_name, None) == self.cookie_value: return self.app(environ, start_response) elif password == self.password: res = request.get_response(self.app) res.set_cookie(self.cookie_name, self.cookie_value, max_age=self.lifetime, path='/', domain=self.domain) return res(environ, start_response) else: template = self.loader.load('form.pt') res = Response(content_type='text/html', charset='utf8', body=template.render()) return res(environ, start_response)
def __init__(self, app, global_conf, password, cookie_name, cookie_value, domain, lifetime=DEFAULT_COOKIE_LIFETIME, default_message=''): self.app = app self.password = password self.cookie_name = cookie_name self.cookie_value = cookie_value self.domain = domain self.lifetime = lifetime self.default_message = default_message self.loader = TemplateLoader(os.path.dirname(__file__))
def OutputTemplate(self, user): logger = logging.getLogger("SlackBot") logger.debug(user['user_id'] + " asked for a template refresh") self.SetupJson() # Two stages, the first is to order the user id by timestamp, then pull in order findLatest = {} findPosts = {} problems = False twUrl = "http://twitter.com/" for key, val in self.botJson['updates'].iteritems(): findPosts[key] = self.botJson['updates'][key]['ts'] findLatest = sorted(findPosts.items(), key=itemgetter(1), reverse=True) tdata = [] for key, val in findLatest: user_id = self.botJson['updates'][key]['user_id'] # Is this a hidden post? if user_id in self.botJson['hidden']: continue text = str(self.botJson['updates'][key]['text'].encode("utf-8")) text = text.replace("\"", "\\\"") logger.debug("Text to output: " + text) ts = self.botJson['updates'][key]['ts'] ''' Reasons not to continue. We will mark a problem and skip. ''' if 'name' not in self.botJson['users'][user_id]: problems = True continue if 'image' not in self.botJson['users'][user_id]: problems = True continue if 'twitter' not in self.botJson['users'][user_id]: problems = True continue if 'email' not in self.botJson['users'][user_id]: problems = True continue logger.debug(self.botJson['users'][user_id]['name']) tdata.append({ "text": cgi.escape(text), #self.html_parser.escape(text), "name": self.botJson['users'][user_id]['name'], "image": self.botJson['users'][user_id]['image'], "twitter": twUrl + str(self.botJson['users'][user_id]['twitter']), "email": self.botJson['users'][user_id]['email'], "ts": datetime.datetime.fromtimestamp(float(ts)).strftime('%Y-%m-%d %H:%M:%S') }) pt_loader = TemplateLoader(['html/'], auto_reload=True) template = pt_loader.load('index.template') with open(botData.output_file, 'w') as template_out: template_out.write(template(users=tdata)) template_out.close() if problems is True: response = "<@" + user['user_id'] + ">: There was a problem outputting the template, but I did what I can.\n" response += self.FindLazyUsers() return response else: return "<@" + user['user_id'] + ">: I have refreshed the template."
def OutputTemplate(self, user): logger = logging.getLogger("SlackBot") logger.debug(user['user_id'] + " asked for a template refresh") self.SetupJson() # Two stages, the first is to order the user id by timestamp, then pull in order findLatest = {} findPosts = {} problems = False twUrl = "http://twitter.com/" for key, val in self.botJson['updates'].iteritems(): findPosts[key] = self.botJson['updates'][key]['ts'] findLatest = sorted(findPosts.items(), key=itemgetter(1), reverse=True) tdata = [] for key, val in findLatest: user_id = self.botJson['updates'][key]['user_id'] # Is this a hidden post? if user_id in self.botJson['hidden']: continue text = str(self.botJson['updates'][key]['text'].encode("utf-8")) text = text.replace("\"", "\\\"") logger.debug("Text to output: " + text) ts = self.botJson['updates'][key]['ts'] ''' Reasons not to continue. We will mark a problem and skip. ''' if 'name' not in self.botJson['users'][user_id]: problems = True continue if 'image' not in self.botJson['users'][user_id]: problems = True continue if 'twitter' not in self.botJson['users'][user_id]: problems = True continue if 'email' not in self.botJson['users'][user_id]: problems = True continue logger.debug(self.botJson['users'][user_id]['name']) tdata.append({ "text": cgi.escape(text), #self.html_parser.escape(text), "name": self.botJson['users'][user_id]['name'], "image": self.botJson['users'][user_id]['image'], "twitter": twUrl + str(self.botJson['users'][user_id]['twitter']), "email": self.botJson['users'][user_id]['email'], "ts": datetime.datetime.fromtimestamp( float(ts)).strftime('%Y-%m-%d %H:%M:%S') }) pt_loader = TemplateLoader(['html/'], auto_reload=True) template = pt_loader.load('index.template') with open(botData.output_file, 'w') as template_out: template_out.write(template(users=tdata)) template_out.close() if problems is True: response = "<@" + user[ 'user_id'] + ">: There was a problem outputting the template, but I did what I can.\n" response += self.FindLazyUsers() return response else: return "<@" + user['user_id'] + ">: I have refreshed the template."