File size: 3,095 Bytes
be1a7b1
 
 
 
 
5e7ce2b
be1a7b1
5e7ce2b
be1a7b1
 
 
 
5e7ce2b
be1a7b1
 
5e7ce2b
be1a7b1
 
 
 
 
 
 
 
 
 
5e7ce2b
be1a7b1
 
 
5e7ce2b
be1a7b1
 
 
 
 
 
 
5e7ce2b
be1a7b1
 
 
5e7ce2b
be1a7b1
 
 
 
 
 
 
 
 
 
 
5e7ce2b
be1a7b1
 
 
 
 
 
 
 
 
 
 
 
5e7ce2b
be1a7b1
 
 
 
 
 
5e7ce2b
be1a7b1
 
5e7ce2b
be1a7b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from flask import Flask, request, jsonify
import os
import json
import zipfile
import requests

app = Flask(__name__)

class APIService:
    """ Basisklasse für alle API-Dienste. """
    def __init__(self, api_key):
        self.api_key = api_key

    def fetch(self, *args, **kwargs):
        raise NotImplementedError("Diese Methode muss von Unterklassen implementiert werden.")

class SynonymAPI(APIService):
    """ API-Dienst für Synonyme. """
    def fetch(self, word):
        url = f"https://lingua-robot.p.rapidapi.com/language/v1/synonyms?word={word}"
        headers = {
            'x-rapidapi-key': self.api_key,
            'x-rapidapi-host': "lingua-robot.p.rapidapi.com"
        }
        response = requests.get(url, headers=headers)
        return response.json()['entries'][0]['synonyms'] if response.status_code == 200 else []

class AliasManager:
    """ Verwaltung von Aliasen. """
    aliases = []

    @classmethod
    def add_alias(cls, alias_name, command, description):
        cls.aliases.append({
            "alias_name": alias_name,
            "command": command,
            "description": description
        })

    @classmethod
    def list_aliases(cls):
        return cls.aliases

class BackupManager:
    """ Backup-Funktionalitäten """
    @staticmethod
    def create_backup():
        backup_filename = "project_backup.zip"
        with zipfile.ZipFile(backup_filename, 'w') as zipf:
            for root, dirs, files in os.walk("."):
                for file in files:
                    if file not in ["project_backup.zip"]:
                        zipf.write(os.path.join(root, file))
        return backup_filename

# API-Routen
@app.route('/aliases', methods=['GET', 'POST'])
def manage_aliases():
    if request.method == 'POST':
        data = request.json
        alias_name = data.get('alias_name')
        command = data.get('command')
        description = data.get('description')
        AliasManager.add_alias(alias_name, command, description)
        return jsonify({"status": "Alias erfolgreich erstellt", "alias_name": alias_name})
    else:
        return jsonify(AliasManager.list_aliases())

@app.route('/create-script', methods=['POST'])
def create_script():
    data = request.json
    script_name = data.get('script_name')
    content = data.get('content')
    description = data.get('description')

    with open(f"my_scripts/{script_name}.py", "w") as script_file:
        script_file.write(content)

    return jsonify({"status": "Skript erfolgreich erstellt", "script_name": script_name})

@app.route('/create-backup', methods=['POST'])
def create_backup():
    backup_filename = BackupManager.create_backup()
    return jsonify({"status": "Backup erfolgreich erstellt", "backup_filename": backup_filename})

@app.route('/tasks', methods=['GET'])
def get_tasks():
    if os.path.exists("tasks.json"):
        with open("tasks.json", "r") as tasks_file:
            tasks = json.load(tasks_file)
    else:
        tasks = []
    return jsonify(tasks)

# Start des Servers
if __name__ == '__main__':
    app.run(debug=True)