def timetable(iata_code): @after_this_request def add_header(response): response.headers['Content-type'] = 'application/json' return response parser = registry.initialize(iata_code) records = parser.run() return records.to_json()
def get(self, iata_code, _type=None): client = tornado.httpclient.AsyncHTTPClient() try: parser = registry.initialize(iata_code) except TypeError: self.set_status(404) self.write({ 'status': 'error', 'message': 'Airport {} not found'.format(iata_code) }) self.finish() else: records = yield parser.run_async() self.write(records.to_json()) self.set_header('Content-Type', 'application/json') self.finish()