From fbacdadd73c65ac7754a209b791366fc931e0a6a Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 24 Jun 2024 21:13:25 +0200 Subject: [PATCH] added intern text generator --- deploy-production.sh | 35 +++++++++++++++++++ .../shx-intern-texte-generator/index.json | 21 +++++++++++ .../shx-intern-texte-generator/script.py | 30 ++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100755 deploy-production.sh create mode 100644 groupTasks/groups/shx-intern-texte-generator/index.json create mode 100644 groupTasks/groups/shx-intern-texte-generator/script.py diff --git a/deploy-production.sh b/deploy-production.sh new file mode 100755 index 0000000..ef3535a --- /dev/null +++ b/deploy-production.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +#screen -dmS admin-dashboard-backend | exit 0 +#screen -S admin-dashboard-backend -p 0 -X stuff 'go run main.go\n' + +# Set variables +BACKUP_DIR="backups" +DATE=$(date +'%Y-%m-%d_%H-%M-%S') +MAIN_FILE="main" +BACKUP_FILE="$BACKUP_DIR/main-$DATE" +MAX_BACKUPS=10 + +# Create backup directory if it doesn't exist +mkdir -p $BACKUP_DIR + +# Check if the main file exists and move it to the backup directory with the current date and time +if [ -f $MAIN_FILE ]; then + mv $MAIN_FILE $BACKUP_FILE + echo "Backup of '$MAIN_FILE' created at '$BACKUP_FILE'" +else + echo "No existing main file to backup." +fi + +# Ensure there are at most MAX_BACKUPS backups in the directory +BACKUPS_COUNT=$(ls $BACKUP_DIR | wc -l) +if [ $BACKUPS_COUNT -gt $MAX_BACKUPS ]; then + BACKUPS_TO_DELETE=$(expr $BACKUPS_COUNT - $MAX_BACKUPS) + ls -t $BACKUP_DIR | tail -n $BACKUPS_TO_DELETE | while read -r file; do + rm "$BACKUP_DIR/$file" + echo "Deleted old backup '$BACKUP_DIR/$file'" + done +fi + +go build main.go +sudo systemctl restart admin-dashboard-backend.service \ No newline at end of file diff --git a/groupTasks/groups/shx-intern-texte-generator/index.json b/groupTasks/groups/shx-intern-texte-generator/index.json new file mode 100644 index 0000000..5dd5ce3 --- /dev/null +++ b/groupTasks/groups/shx-intern-texte-generator/index.json @@ -0,0 +1,21 @@ +{ + "category": "Shinnex", + "name": "Interner Texte Generator", + "globalInputs": [], + "tasks": [ + { + "name": "Internen finalen Text für 3D Drucker generieren ", + "onFinish": "pause", + "undoPossible": false, + "repeatPossible": true, + "scriptPath": "script.py", + "parameters": [ + { + "parameterName": "text_style", + "type": "textarea", + "displayName": "Texteigenschaften (von Shopify Warenkorb kopieren)" + } + ] + } + ] +} \ No newline at end of file diff --git a/groupTasks/groups/shx-intern-texte-generator/script.py b/groupTasks/groups/shx-intern-texte-generator/script.py new file mode 100644 index 0000000..04aee77 --- /dev/null +++ b/groupTasks/groups/shx-intern-texte-generator/script.py @@ -0,0 +1,30 @@ +import requests +import json +import sys + +json_object = json.loads(sys.argv[1]) +text_style = json_object["text_style"] + +if text_style is None: + print("Missing required parameters") + sys.exit(1) + +text_style = text_style["value"] + +print("text_style", text_style) + +response = requests.post( + url="https://render.shinnex.de/intern", + headers={ + "X-Api-Key": "OTp2wNND-TWdW-1VIl-jeOI-L10Lc0O6YvDZ", + "Content-Type": "application/json" + }, + json={ + "data": text_style, + }) + +if response.status_code != 200: + print(f"Req err, status code: {response.status_code}") + sys.exit(1) + +print("res status_code", response.status_code) \ No newline at end of file