def jsrun(aid, ua=None, l=200): global jsrun_logger, jsrun_out jsrun_logger.seek(0) if not o(aid): print "Object {} has no content".format(aid) return global _jw t = ThugAPI('', configuration_path=JSCONFPATH) t.set_no_fetch() t.log_init('') url = 'http://{}{}'.format(conversations[aid].host, conversations[aid].uri) w = t.window_from_file(o(aid), url, offline_content=conversations_r, max_len=l) # Customise referer and user-agent, the latter is not # especially pretty but what can you do - we cannot have # personality files for everything we see t.set_referer(conversations[aid].referer) if ua: w._navigator.personality['userAgent'] = ua else: w._navigator.personality['userAgent'] \ = conversations[aid].user_agent t.run(w) _jw = w jsrun_out = jsrun_logger.getvalue() p(jsrun_out)