1 Commits

Author SHA1 Message Date
santiagosayshey
a82e8d31fe ANSI Escape colors not being printed properly (#34)
* Added config setting to allow ansi coloring
* Adjusted README for configuring ansi support
2024-02-08 08:44:01 +10:30
3 changed files with 50 additions and 18 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -17,6 +17,7 @@ instances:
settings:
export_path: "./exports"
import_path: "./imports"
ansi_colors: "true"
"""