Advertisement
max2201111

Untitled

Jun 11th, 2024
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | Science | 0 0
  1. from flask import Flask, render_template, request, jsonify
  2. import requests
  3. from bs4 import BeautifulSoup
  4.  
  5. app = Flask(__name__)
  6.  
  7. @app.route('/')
  8. def index():
  9.     return render_template('index.html')
  10.  
  11. def fetch_translation(term):
  12.     url = f'https://slovnik.seznam.cz/preklad/anglicky_cesky/{term}'
  13.     response = requests.get(url)
  14.     return response.text
  15.  
  16. @app.route('/translate', methods=['POST'])
  17. def translate():
  18.     term = request.json.get('term')
  19.     url = f'https://slovnik.seznam.cz/preklad/anglicky_cesky/{term}'
  20.     response = requests.get(url)
  21.     if response.status_code == 200:
  22.         if response:
  23.             translation = response.text
  24.             return jsonify(success=True, translation=translation)
  25.         else:
  26.             return jsonify(success=False, error='Translation not found')
  27.     return jsonify(success=False, error='Translation service unavailable')
  28.  
  29. if __name__ == '__main__':
  30.     app.run(port=5000, debug=True)
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement