Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, render_template, request, jsonify
- import requests
- from bs4 import BeautifulSoup
- app = Flask(__name__)
- @app.route('/')
- def index():
- return render_template('index.html')
- def fetch_translation(term):
- url = f'https://slovnik.seznam.cz/preklad/anglicky_cesky/{term}'
- response = requests.get(url)
- return response.text
- @app.route('/translate', methods=['POST'])
- def translate():
- term = request.json.get('term')
- url = f'https://slovnik.seznam.cz/preklad/anglicky_cesky/{term}'
- response = requests.get(url)
- if response.status_code == 200:
- if response:
- translation = response.text
- return jsonify(success=True, translation=translation)
- else:
- return jsonify(success=False, error='Translation not found')
- return jsonify(success=False, error='Translation service unavailable')
- if __name__ == '__main__':
- app.run(port=5000, debug=True)
Add Comment
Please, Sign In to add comment