コード例 #1
0
 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')
コード例 #2
0
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 ''
コード例 #3
0
ファイル: generate_text.py プロジェクト: Aless-T/ord-schema
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)
コード例 #4
0
ファイル: search.py プロジェクト: Aless-T/ord-schema
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 ''