75062dbf5e
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
64 lines
2.7 KiB
Python
64 lines
2.7 KiB
Python
from flask import Blueprint, request, jsonify
|
|
import random
|
|
from util.logger import logger
|
|
from auth.token import verify_token
|
|
|
|
lorem_blueprint = Blueprint('lorem_tool', __name__)
|
|
|
|
WORDS = [
|
|
"lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit",
|
|
"sed", "do", "eiusmod", "tempor", "incididunt", "ut", "labore", "et", "dolore",
|
|
"magna", "aliqua", "enim", "ad", "minim", "veniam", "quis", "nostrud",
|
|
"exercitation", "ullamco", "laboris", "nisi", "aliquip", "ex", "ea", "commodo",
|
|
"consequat", "duis", "aute", "irure", "reprehenderit", "voluptate", "velit",
|
|
"esse", "cillum", "eu", "fugiat", "nulla", "pariatur", "excepteur", "sint",
|
|
"occaecat", "cupidatat", "non", "proident", "sunt", "culpa", "qui", "officia",
|
|
"deserunt", "mollit", "anim", "id", "est", "laborum", "perspiciatis", "unde",
|
|
"omnis", "iste", "natus", "error", "voluptatem", "accusantium", "doloremque",
|
|
"laudantium", "totam", "rem", "aperiam", "eaque", "ipsa", "quae", "ab", "illo",
|
|
"inventore", "veritatis", "quasi", "architecto", "beatae", "vitae", "dicta",
|
|
"explicabo", "nemo", "ipsam", "quia", "voluptas", "aspernatur", "odit",
|
|
"fugit", "magni", "dolores", "ratione", "sequi", "nesciunt", "neque", "porro",
|
|
"quisquam", "adipisci", "numquam", "eius", "modi", "tempora", "incidunt",
|
|
"soluta", "nobis", "eligendi", "optio", "cumque", "nihil", "impedit", "minus",
|
|
"maxime", "placeat", "facere", "possimus", "omnis", "assumenda", "repellendus",
|
|
]
|
|
|
|
|
|
def make_sentence():
|
|
word_count = random.randint(8, 15)
|
|
words = [random.choice(WORDS) for _ in range(word_count)]
|
|
return words[0].capitalize() + ' ' + ' '.join(words[1:]) + '.'
|
|
|
|
|
|
def make_paragraph():
|
|
sentence_count = random.randint(4, 6)
|
|
return ' '.join(make_sentence() for _ in range(sentence_count))
|
|
|
|
|
|
@lorem_blueprint.route('/api/lorem/generate', methods=['POST'])
|
|
def generate_lorem():
|
|
user = verify_token()
|
|
if not user:
|
|
return jsonify({"message": "Nicht autorisiert"}), 401
|
|
try:
|
|
data = request.get_json() or {}
|
|
gen_type = data.get("type", "sentences")
|
|
count = int(data.get("count", 3))
|
|
count = max(1, min(20, count))
|
|
|
|
if gen_type == "words":
|
|
text = ' '.join(random.choice(WORDS) for _ in range(count))
|
|
elif gen_type == "sentences":
|
|
text = ' '.join(make_sentence() for _ in range(count))
|
|
elif gen_type == "paragraphs":
|
|
text = '\n\n'.join(make_paragraph() for _ in range(count))
|
|
else:
|
|
return jsonify({"message": "Ungültiger Typ"}), 400
|
|
|
|
return jsonify({"text": text})
|
|
|
|
except Exception as e:
|
|
logger.error(f"Fehler lorem ipsum: {e}")
|
|
return jsonify({"message": "Fehler bei der Generierung"}), 500
|