Initial Commit
This commit is contained in:
120
scripts/enable_news_manager.py
Normal file
120
scripts/enable_news_manager.py
Normal file
@@ -0,0 +1,120 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
|
||||
def enable_news_manager():
|
||||
"""Enable the news manager in the configuration"""
|
||||
config_path = "config/config.json"
|
||||
|
||||
try:
|
||||
# Load current config
|
||||
with open(config_path, 'r') as f:
|
||||
config = json.load(f)
|
||||
|
||||
# Enable news manager
|
||||
if 'news_manager' not in config:
|
||||
print("News manager configuration not found!")
|
||||
return False
|
||||
|
||||
config['news_manager']['enabled'] = True
|
||||
|
||||
# Save updated config
|
||||
with open(config_path, 'w') as f:
|
||||
json.dump(config, f, indent=4)
|
||||
|
||||
print("SUCCESS: News manager enabled successfully!")
|
||||
print(f"Enabled feeds: {config['news_manager']['enabled_feeds']}")
|
||||
print(f"Headlines per feed: {config['news_manager']['headlines_per_feed']}")
|
||||
print(f"Update interval: {config['news_manager']['update_interval']} seconds")
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"ERROR: Error enabling news manager: {e}")
|
||||
return False
|
||||
|
||||
def disable_news_manager():
|
||||
"""Disable the news manager in the configuration"""
|
||||
config_path = "config/config.json"
|
||||
|
||||
try:
|
||||
# Load current config
|
||||
with open(config_path, 'r') as f:
|
||||
config = json.load(f)
|
||||
|
||||
# Disable news manager
|
||||
if 'news_manager' in config:
|
||||
config['news_manager']['enabled'] = False
|
||||
|
||||
# Save updated config
|
||||
with open(config_path, 'w') as f:
|
||||
json.dump(config, f, indent=4)
|
||||
|
||||
print("SUCCESS: News manager disabled successfully!")
|
||||
else:
|
||||
print("News manager configuration not found!")
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
print(f"ERROR: Error disabling news manager: {e}")
|
||||
return False
|
||||
|
||||
def show_status():
|
||||
"""Show current news manager status"""
|
||||
config_path = "config/config.json"
|
||||
|
||||
try:
|
||||
with open(config_path, 'r') as f:
|
||||
config = json.load(f)
|
||||
|
||||
if 'news_manager' not in config:
|
||||
print("News manager configuration not found!")
|
||||
return
|
||||
|
||||
news_config = config['news_manager']
|
||||
|
||||
print("News Manager Status:")
|
||||
print("=" * 30)
|
||||
print(f"Enabled: {news_config.get('enabled', False)}")
|
||||
print(f"Update Interval: {news_config.get('update_interval', 300)} seconds")
|
||||
print(f"Scroll Speed: {news_config.get('scroll_speed', 2)} pixels/frame")
|
||||
print(f"Scroll Delay: {news_config.get('scroll_delay', 0.02)} seconds/frame")
|
||||
print(f"Headlines per Feed: {news_config.get('headlines_per_feed', 2)}")
|
||||
print(f"Enabled Feeds: {news_config.get('enabled_feeds', [])}")
|
||||
print(f"Rotation Enabled: {news_config.get('rotation_enabled', True)}")
|
||||
print(f"Rotation Threshold: {news_config.get('rotation_threshold', 3)}")
|
||||
print(f"Font Size: {news_config.get('font_size', 12)}")
|
||||
|
||||
custom_feeds = news_config.get('custom_feeds', {})
|
||||
if custom_feeds:
|
||||
print("Custom Feeds:")
|
||||
for name, url in custom_feeds.items():
|
||||
print(f" {name}: {url}")
|
||||
else:
|
||||
print("No custom feeds configured")
|
||||
|
||||
except Exception as e:
|
||||
print(f"ERROR: Error reading configuration: {e}")
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python3 scripts/enable_news_manager.py [enable|disable|status]")
|
||||
sys.exit(1)
|
||||
|
||||
command = sys.argv[1].lower()
|
||||
|
||||
if command == "enable":
|
||||
enable_news_manager()
|
||||
elif command == "disable":
|
||||
disable_news_manager()
|
||||
elif command == "status":
|
||||
show_status()
|
||||
else:
|
||||
print("Invalid command. Use: enable, disable, or status")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
150
scripts/install_dependencies_apt.py
Normal file
150
scripts/install_dependencies_apt.py
Normal file
@@ -0,0 +1,150 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Alternative dependency installer that tries apt packages first,
|
||||
then falls back to pip with --break-system-packages
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
def install_via_apt(package_name):
|
||||
"""Try to install a package via apt."""
|
||||
try:
|
||||
# Map pip package names to apt package names
|
||||
apt_package_map = {
|
||||
'flask': 'python3-flask',
|
||||
'flask_socketio': 'python3-flask-socketio',
|
||||
'PIL': 'python3-pil',
|
||||
'socketio': 'python3-socketio',
|
||||
'eventlet': 'python3-eventlet',
|
||||
'freetype': 'python3-freetype',
|
||||
'psutil': 'python3-psutil',
|
||||
'werkzeug': 'python3-werkzeug',
|
||||
'numpy': 'python3-numpy',
|
||||
'requests': 'python3-requests',
|
||||
'python-dateutil': 'python3-dateutil',
|
||||
'pytz': 'python3-tz',
|
||||
'geopy': 'python3-geopy',
|
||||
'unidecode': 'python3-unidecode',
|
||||
'websockets': 'python3-websockets',
|
||||
'websocket-client': 'python3-websocket-client'
|
||||
}
|
||||
|
||||
apt_package = apt_package_map.get(package_name, f'python3-{package_name}')
|
||||
|
||||
print(f"Trying to install {apt_package} via apt...")
|
||||
subprocess.check_call([
|
||||
'sudo', 'apt', 'update'
|
||||
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
subprocess.check_call([
|
||||
'sudo', 'apt', 'install', '-y', apt_package
|
||||
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
print(f"Successfully installed {apt_package} via apt")
|
||||
return True
|
||||
|
||||
except subprocess.CalledProcessError:
|
||||
print(f"Failed to install {package_name} via apt, will try pip")
|
||||
return False
|
||||
|
||||
def install_via_pip(package_name):
|
||||
"""Install a package via pip with --break-system-packages."""
|
||||
try:
|
||||
print(f"Installing {package_name} via pip...")
|
||||
subprocess.check_call([
|
||||
sys.executable, '-m', 'pip', 'install', '--break-system-packages', package_name
|
||||
])
|
||||
print(f"Successfully installed {package_name} via pip")
|
||||
return True
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Failed to install {package_name} via pip: {e}")
|
||||
return False
|
||||
|
||||
def check_package_installed(package_name):
|
||||
"""Check if a package is already installed."""
|
||||
try:
|
||||
__import__(package_name)
|
||||
return True
|
||||
except ImportError:
|
||||
return False
|
||||
|
||||
def main():
|
||||
"""Main installation function."""
|
||||
print("Installing dependencies for LED Matrix Web Interface V2...")
|
||||
|
||||
# List of required packages
|
||||
required_packages = [
|
||||
'flask',
|
||||
'flask_socketio',
|
||||
'PIL',
|
||||
'socketio',
|
||||
'eventlet',
|
||||
'freetype',
|
||||
'psutil',
|
||||
'werkzeug',
|
||||
'numpy',
|
||||
'requests',
|
||||
'python-dateutil',
|
||||
'pytz',
|
||||
'geopy',
|
||||
'unidecode',
|
||||
'websockets',
|
||||
'websocket-client'
|
||||
]
|
||||
|
||||
failed_packages = []
|
||||
|
||||
for package in required_packages:
|
||||
if check_package_installed(package):
|
||||
print(f"{package} is already installed")
|
||||
continue
|
||||
|
||||
# Try apt first, then pip
|
||||
if not install_via_apt(package):
|
||||
if not install_via_pip(package):
|
||||
failed_packages.append(package)
|
||||
|
||||
# Install packages that don't have apt equivalents
|
||||
special_packages = [
|
||||
'timezonefinder==6.2.0',
|
||||
'google-auth-oauthlib==1.0.0',
|
||||
'google-auth-httplib2==0.1.0',
|
||||
'google-api-python-client==2.86.0',
|
||||
'spotipy',
|
||||
'icalevents',
|
||||
'python-engineio'
|
||||
]
|
||||
|
||||
for package in special_packages:
|
||||
if not install_via_pip(package):
|
||||
failed_packages.append(package)
|
||||
|
||||
# Install rgbmatrix module from local source
|
||||
print("Installing rgbmatrix module...")
|
||||
try:
|
||||
rgbmatrix_path = Path(__file__).parent / 'rpi-rgb-led-matrix-master' / 'bindings' / 'python'
|
||||
if rgbmatrix_path.exists():
|
||||
subprocess.check_call([
|
||||
sys.executable, '-m', 'pip', 'install', '--break-system-packages', '-e', str(rgbmatrix_path)
|
||||
], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
print("rgbmatrix module installed successfully")
|
||||
else:
|
||||
print("Warning: rgbmatrix source not found")
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Failed to install rgbmatrix module: {e}")
|
||||
failed_packages.append('rgbmatrix')
|
||||
|
||||
if failed_packages:
|
||||
print(f"\nFailed to install the following packages: {failed_packages}")
|
||||
print("You may need to install them manually or check your system configuration.")
|
||||
return False
|
||||
else:
|
||||
print("\nAll dependencies installed successfully!")
|
||||
return True
|
||||
|
||||
if __name__ == '__main__':
|
||||
success = main()
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in New Issue
Block a user