HTTP 프로토콜 내용보기
Flask 설치하기
https://asciinema.org/a/176653
Flask code template
from flask import Flask, jsonify app = Flask(__name__) @app.route('/') def index(): return "Hello World!" @app.route('/text') def text(): data = { 'this_is_int': 1, 'this_is_dict': {'a': 1} } return jsonify(data) if __name__ == "__main__": app.run(host='0.0.0.0', port=5000)
Kakaotalk code template
from flask import Flask, request, jsonify app = Flask(__name__) @app.route('/keyboard') def Keyboard(): data_to_send = { "type": "text", "buttons": [] } return jsonify(data_to_send) @app.route('/message', methods=['POST']) def Message(): data_received = request.get_json() content = data_received['content'] return jsonify({'message': {"text": content}}) if __name__ == "__main__": app.run(host='0.0.0.0', port=5000)
Install googletrans
Translate bot code
from flask import Flask, request, jsonify from googletrans import Translator app = Flask(__name__) translator = Translator() @app.route('/keyboard') def Keyboard(): data_to_send = { "type": "text", "buttons": [] } return jsonify(data_to_send) @app.route('/message', methods=['POST']) def Message(): data_received = request.get_json() content = data_received['content'] translated = translator.translate(content, dest='fr').text return jsonify({'message': {"text": translated}}) if __name__ == "__main__": app.run(host='0.0.0.0', port=5000)
발표자료
'여러가지' 카테고리의 다른 글
Oracle Cloud 에서 Kernel panic난 인스턴스 복구 삽질기 (0) | 2024.02.28 |
---|---|
wework 수업자료 - day3 (0) | 2018.04.20 |
wework 수업자료 (0) | 2018.03.27 |
Spoofing TEST Page by Flask (0) | 2016.10.07 |
kill process by result of ps -ef (0) | 2016.10.07 |