-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
68 lines (48 loc) · 1.32 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Dustin Michels
3 March 2017
"""
import flask
from flask import render_template, request
import dna_to_text
import text_to_dna
app = flask.Flask(__name__)
@app.route("/")
def get_main_page():
return render_template("index.html")
@app.route("/about")
def about():
return render_template("about.html")
@app.route("/textToDNA")
def textToDNA():
# get args from url
argsMultiDict = request.args
argsDict = argsMultiDict.to_dict()
text = argsDict["inputString"]
try:
dna = text_to_dna.get_dna(text)
except ValueError as e:
return_str = "Error! Can't convert that text into DNA.\n\n" + str(e)
return return_str
return dna
@app.route("/dnaToText")
def dnaToText():
# get args from url
args_multi_dict = request.args
args_dict = args_multi_dict.to_dict()
dna = args_dict["inputString"]
try:
message = dna_to_text.get_message(dna)
except ValueError:
return "Error! That might not be valid DNA."
return message
# if __name__ == "__main__":
# """
# Example usage: 'python3 api.py localhost 5000'
# """
# if len(sys.argv) != 3:
# print("Usage: {0} host port".format(sys.argv[0]), file=sys.stderr)
# exit()
# host = sys.argv[1]
# port = int(sys.argv[2])
# app.run(host=host, port=port, debug=True)