def handler(request: RequestT) -> ResponseT: money = request.query.get("money") if not money: show_rubles = "" show_penny = "" show_text = "Input count of money!" elif wrong_words(money[0]) and is_number(money[0]) or money[0].isdigit(): text, rubles, penny = solution(money[0]) show_rubles = "" show_penny = "" for i in rubles: show_rubles += f"<h2><p style = 'color:#E6E6FA'>{i}</p></h2>" for j in penny: show_penny += f"<h2><p style = 'color:#E6E6FA'>{j}</p></h2>" show_text = text else: show_rubles = "" show_penny = "" show_text = "Wrong data!" context = { "show_rubles": show_rubles, "show_penny": show_penny, "show_text": show_text } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: a_raw = request.query.get("a", [""])[0] or "" b_raw = request.query.get("b", [""])[0] or "" c_raw = request.query.get("c", [""])[0] or "" can_into_complex = bool(request.query.get("can_into_complex")) coefficients = CoefficientsT(a=a_raw, b=b_raw, c=c_raw) try: result = solution(coefficients, can_into_complex) except ValueError as err: result = f"нет решений ({err})" context = { "a": a_raw, "b": b_raw, "c": c_raw, "can_into_complex": "checked" * can_into_complex, "result": result, } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: integer1 = request.query.get("integer1") integer2 = request.query.get("integer2") if not integer1 and not integer2: text = "Input integers..." show_count = "" elif integer1 and not integer2: text = "Input second integer..." show_count = "" elif not integer1 and integer2: text = "Input first integer..." show_count = "" else: numbers, count = solution(integer1[0], integer2[0]) if type(numbers) is list: text = "--> " for i in numbers: text += f"{i} " show_count = f"Count of numbers --> {count}" else: text = numbers show_count = count context = { "show_text": text, "show_count": show_count, } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: client_data = request.post_req.get("number") response = ResponseT() client_name = get_client(request) if not client_name: client_name = os.urandom(8).hex() response.cookies["session"] = client_name response.cookies["session"]["path"] = "/" if not find_task(client_name): add_task(client_name) if not client_data: result = "Input number..." else: if client_data[0] == "stop": sum_numbers = calc_sum(client_name) clear_file = document_cleaning(client_name) result = f"Answer: {sum_numbers}. {clear_file}" elif client_data[0].isnumeric(): number = int(client_data[0]) result = f"The number {add_number(client_name, number)} was written down..." else: result = "Wrong input!" context = {"show_text": result} document = render_template(TEMPLATE, context) response.payload = document return response
def handler(request: RequestT) -> ResponseT: dimension = request.query.get("dimension") if not dimension: text = "Input matrix dimension..." matrix = "" else: my_matrix = solution(dimension[0]) if type(my_matrix) is list: matrix = "" text = "matrix:" for i in my_matrix: matrix += f"<h2 style = 'color:#FFA07A;font-family: courier, monospace;'>{i}</h2>" else: text = my_matrix matrix = "" context = { "show_text": text, "show_matrix": matrix, } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(_request: RequestT) -> ResponseT: context = {"random_number": randint(100000, 999999)} document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handle_404(request: RequestT) -> ResponseT: response = ResponseT( content_type="text/plain", payload=f"OOPS! endpoint {request.path} not found!", status=HTTPStatus.NOT_FOUND, ) return response
def handle_500(_request: RequestT) -> ResponseT: response = ResponseT( content_type="text/plain", payload=traceback.format_exc(), status=HTTPStatus.INTERNAL_SERVER_ERROR, ) return response
def handler(_request: RequestT) -> ResponseT: payload = str(1 / 0) response = ResponseT( payload=payload, status=HTTPStatus.INTERNAL_SERVER_ERROR, ) return response
def handler(request: RequestT) -> ResponseT: matrix_n = request.query.get("lines_n") matrix_m = request.query.get("columns_m") if not matrix_n and not matrix_m: text = "Input dimension(n x m)..." matrix = "" sum_digits = "" max_digit = "" min_digit = "" elif matrix_n and not matrix_m: text = "Input number of columns(m)..." matrix = "" sum_digits = "" max_digit = "" min_digit = "" elif not matrix_n and matrix_m: text = "Input number of lines(n)..." matrix = "" sum_digits = "" max_digit = "" min_digit = "" else: my_matrix, sum_elem, max_elem, min_elem = solution( matrix_n[0], matrix_m[0]) if type(my_matrix) is list: matrix = "" sum_digits = f"Sum of digits --> {sum_elem}" max_digit = f"Max digit --> {max_elem}" min_digit = f"Min digit --> {min_elem}" text = "matrix:" for i in my_matrix: matrix += f"<h2 style = 'color:#FFA07A;font-family: courier, monospace;'>{i}</h2>" else: text = my_matrix sum_digits = sum_elem max_digit = max_elem min_digit = min_elem matrix = "" context = { "show_text": text, "show_matrix": matrix, "show_sum": sum_digits, "show_max": max_digit, "show_min": min_digit, } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: name = request.query.get("name", [""])[0] context = { "input_name": name, "greeting_name": name or "anonymous", } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: sentence = request.query.get("sentence", [""])[0] or "" result = solution(sentence) if sentence else "" context = { "sentence": sentence, "result": result, } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: sentence = request.query.get("sentence", [""])[0] or "" result = solution(sentence) context = { "sentence": sentence, "result": ["отсутствует", "присутствует"][result], } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: age = request.query.get("age") result = solution(age[0]) if age else "Input your age!" context = { "show_text": result } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: number = request.query.get("number") if not number: result = "Input number for find factorial..." else: result = solution(number[0]) context = {"show_result": result} document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: digit = request.query.get("digit") if not digit: result = "Input digit..." else: cube_digit = solution(digit[0]) result = f"--> {cube_digit}" context = {"show_text": result} document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: gmail = request.query.get("gmail") if not gmail: result = "Input your Gmail!" else: result = solution(gmail[0]) context = {"show_text": result} document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: integer = request.query.get("integer") if not integer: result = "Input integer..." else: result = f"--> {solution(integer[0])}" context = {"show_text": result} document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: string = request.query.get("string") if not string: result = "Input string..." else: result = solution(string[0]) context = {"show_text": result} document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: money_raw = request.query.get("money", [""])[0] money = parse_decimal(money_raw) result1 = solution1(money) result2 = solution2(money) context = { "money": money_raw, "result1": result1, "result2": result2, } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: email = request.query.get("email", [""])[0] try: solution(email) result = email except ValueError as err: result = str(err) context = { "email": email, "result": result, } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: a_raw = request.query.get("a", [""])[0] b_raw = request.query.get("b", [""])[0] a = int(a_raw) if a_raw else 0 b = int(b_raw) if b_raw else 0 result = f"{a} плюс {b} равно {a + b}" context = { "a": a_raw, "b": b_raw, "result": result, } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: ages = (age1, age2, age3) = [int(request.query.get(f"age{i}", [0])[0]) for i in "123"] age_sum = sum(ages) age_avg = age_sum / len(ages) context = { "age1": age1, "age2": age2, "age3": age3, "age_avg": age_avg, "age_sum": age_sum, "ages": ages, } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: mass_n = request.query.get("lines_n") mass_m = request.query.get("columns_m") if not mass_n and not mass_m: text = "Input dimension(n x m)..." matrix = "" sum_seven = "" elif mass_n and not mass_m: text = "Input number of columns(m)..." matrix = "" sum_seven = "" elif not mass_n and mass_m: text = "Input number of lines(n)..." matrix = "" sum_seven = "" else: my_matrix, count_seven = solution(mass_n[0], mass_m[0]) if type(my_matrix) is list: matrix = "" text = "matrix:" sum_seven = f"Count of seven --> {count_seven}" for i in my_matrix: matrix += f"<h2 style = 'color:#FFA07A;font-family: courier, monospace;'>{i}</h2>" else: text = my_matrix sum_seven = count_seven matrix = "" context = { "show_text": text, "show_matrix": matrix, "show_seven": sum_seven, } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: digit1 = request.query.get("digit1") digit2 = request.query.get("digit2") if not digit1 and not digit2: result = "Input digits..." elif digit1 and not digit2: result = "Input second digit..." elif not digit1 and digit2: result = "Input first digit..." else: result = solution(digit1[0], digit2[0]) context = {"show_text": result} document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handler(request: RequestT) -> ResponseT: age_raw = request.query.get("age", [""])[0] age = ( None if (not age_raw or (isinstance(age_raw, str) and not age_raw.isnumeric())) else int(age_raw) ) if age is not None: legal = solution(age) emoji = ["\N{LOLLIPOP}", "\N{BEER MUG}"][legal] else: emoji = "\N{FACE PALM}\N{ZERO WIDTH JOINER}\N{MALE SIGN}" context = { "age": age_raw, "result": emoji, } document = render_template(TEMPLATE, context) response = ResponseT(payload=document) return response
def handle_404(_request: RequestT) -> ResponseT: payload = render_template("notFound.html") response = ResponseT(payload=payload, status=HTTPStatus.NOT_FOUND) return response
def handler(_request: RequestT) -> ResponseT: document = render_template(TEMPLATE) response = ResponseT(payload=document) return response