def test_html(self): html = generate_text.generate_html(self._reaction) self.assertRegex(html, '<table') self.assertRegex(html, 'hexanone') self.assertRegex(html, 'under oxygen') self.assertRegex(html, '100 rpm') self.assertRegex(html, '40 min') self.assertRegex(html, 'solvent') self.assertRegex(html, '100 °C') self.assertRegex(html, 'dummy_reaction_id')
def render_reaction(): """Receives a serialized Reaction message and returns a block of HTML that contains a visual summary of the reaction.""" reaction = reaction_pb2.Reaction() reaction.ParseFromString(flask.request.get_data()) if not (reaction.inputs or reaction.outcomes): return '' try: html = generate_text.generate_html(reaction) return flask.jsonify(html) except (ValueError, KeyError): return ''
def main(argv): del argv # Only used by app.run(). reaction = message_helpers.load_message(FLAGS.input, reaction_pb2.Reaction) if FLAGS.output_type == 'html': text = generate_text.generate_html(reaction) elif FLAGS.output_type == 'text': text = generate_text.generate_text(reaction) else: raise ValueError(f'unsupported output_type: {FLAGS.output_type}') if FLAGS.output: with open(FLAGS.output, 'w') as f: f.write(text) else: print(text)
def render_reaction(reaction_id): """Renders a reaction as an HTML table with images and text.""" command = query.ReactionIdQuery([reaction_id]) dataset = connect().run_query(command) if len(dataset.reactions) == 0 or len(dataset.reactions) > 1: return flask.abort(404) reaction = dataset.reactions[0] if not (reaction.inputs or reaction.outcomes): return '' try: html = generate_text.generate_html(reaction) return flask.jsonify(html) except (ValueError, KeyError): return ''