mirror of
https://github.com/Dictionarry-Hub/profilarr.git
synced 2026-01-22 10:51:02 +01:00
ANSI Escape colors not being printed properly (#34)
* Added config setting to allow ansi coloring * Adjusted README for configuring ansi support
This commit is contained in:
17
README.md
17
README.md
@@ -26,12 +26,23 @@ Profilarr is a Python-based tool designed to add import/export/sync functionalit
|
||||
- This will create a `config.yml` file in the same directory as `setup.py`.
|
||||
4. Open the `config.yml` file in a text editor.
|
||||
- Add the URL and API key to the master instances of Radarr / Sonarr.
|
||||
- If syncing, add the URL, API key and a name to each extra instance of Radarr / Sonarr.
|
||||
- If syncing, add the URL, API key, and a name to each extra instance of Radarr / Sonarr.
|
||||
- If exporting, adjust the `export_path` to your desired export location.
|
||||
- If importing non Dictionarry files, adjust the `import_path` to your desired import location.
|
||||
5. Save the changes.
|
||||
- If importing non-Dictionary files, adjust the `import_path` to your desired import location.
|
||||
5. Configure ANSI Color Support (Optional):
|
||||
- The Profilarr scripts use ANSI colors in terminal output for better readability. By default, this feature is enabled (`ansi_colors: true`).
|
||||
- **If your terminal does not properly display ANSI colors** (e.g., you see codes like `←[94m` instead of colored text), you may want to disable this feature to improve readability.
|
||||
- To disable ANSI colors, find the `settings` section in your `config.yml` file and change `ansi_colors` to `false`.
|
||||
```yaml
|
||||
settings:
|
||||
export_path: "./exports"
|
||||
import_path: "./imports"
|
||||
ansi_colors: false # Disable ANSI colors if your terminal doesn't support them
|
||||
```
|
||||
6. Save the changes to your `config.yml` file after making the necessary adjustments.
|
||||
|
||||
## 🚀 Usage
|
||||
|
||||
- If using Windows, use `python script.py` or `py script.py`. If on Linux, use `python3 script.py`.
|
||||
|
||||
### Importing
|
||||
|
||||
50
helpers.py
50
helpers.py
@@ -3,6 +3,7 @@ import json
|
||||
import requests
|
||||
from requests.exceptions import ConnectionError, Timeout, TooManyRedirects
|
||||
import json
|
||||
import sys
|
||||
|
||||
class Colors:
|
||||
GREEN = '\033[92m'
|
||||
@@ -20,24 +21,41 @@ class Apps:
|
||||
}
|
||||
|
||||
def print_message(message, message_type='', newline=True):
|
||||
color = Colors.ENDC # default color
|
||||
message_type = message_type.lower()
|
||||
config = load_config()
|
||||
ansi_colors = config['settings']['ansi_colors']
|
||||
|
||||
if ansi_colors:
|
||||
# Initialize color as default.
|
||||
color = Colors.ENDC
|
||||
message_type = message_type.lower()
|
||||
|
||||
if message_type == 'green':
|
||||
color = Colors.GREEN
|
||||
elif message_type == 'red':
|
||||
color = Colors.RED
|
||||
elif message_type == 'yellow':
|
||||
color = Colors.YELLOW
|
||||
elif message_type == 'blue':
|
||||
color = Colors.BLUE
|
||||
elif message_type == 'purple':
|
||||
color = Colors.PURPLE
|
||||
# Assign color based on message type.
|
||||
if message_type == 'green':
|
||||
color = Colors.GREEN
|
||||
elif message_type == 'red':
|
||||
color = Colors.RED
|
||||
elif message_type == 'yellow':
|
||||
color = Colors.YELLOW
|
||||
elif message_type == 'blue':
|
||||
color = Colors.BLUE
|
||||
elif message_type == 'purple':
|
||||
color = Colors.PURPLE
|
||||
|
||||
# Prepare the end color reset code.
|
||||
end_color = Colors.ENDC
|
||||
|
||||
if newline:
|
||||
print(color + message + Colors.ENDC)
|
||||
# Print the colored message.
|
||||
if newline:
|
||||
print(color + message + end_color)
|
||||
else:
|
||||
print(color + message + end_color, end='')
|
||||
else:
|
||||
print(color + message + Colors.ENDC, end='')
|
||||
# Print the message without color if ANSI colors are disabled.
|
||||
if newline:
|
||||
print(message)
|
||||
else:
|
||||
print(message, end='')
|
||||
|
||||
|
||||
|
||||
def load_config():
|
||||
@@ -119,6 +137,7 @@ def make_request(request_type, url, api_key, resource_type, json_payload=None):
|
||||
return None
|
||||
elif response.status_code == 401:
|
||||
print_message("Unauthorized. Check your API key.", "red")
|
||||
sys.exit()
|
||||
elif response.status_code == 409:
|
||||
print_message("Conflict detected. The requested action could not be completed.", "red")
|
||||
else:
|
||||
@@ -126,6 +145,7 @@ def make_request(request_type, url, api_key, resource_type, json_payload=None):
|
||||
except (ConnectionError, Timeout, TooManyRedirects) as e:
|
||||
# Update the message here to suggest checking the application's accessibility
|
||||
print_message("Network error. Make sure the application is running and accessible.", "red")
|
||||
sys.exit()
|
||||
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user