#!/usr/bin/env python3 """ Missing ZW Processor - This reads your .zw files and makes them work """ import yaml import os class ZWProcessor: """Reads and processes your .zw files""" def __init__(self, zw_directory="."): self.zw_dir = zw_directory self.configs = {} def load_all_zw_files(self): """Load all .zw files in directory""" zw_files = [f for f in os.listdir(self.zw_dir) if f.endswith('.zw')] print(f"šŸ” Found ZW files: {zw_files}") for zw_file in zw_files: try: config_name = zw_file.replace('.zw', '') config_data = self.load_zw_file(zw_file) self.configs[config_name] = config_data print(f"āœ… Loaded: {zw_file}") except Exception as e: print(f"āŒ Failed to load {zw_file}: {e}") return self.configs def load_zw_file(self, filename): """Load a single .zw file""" filepath = os.path.join(self.zw_dir, filename) with open(filepath, 'r') as f: content = f.read() # Parse ZW format lines = content.strip().split('\n') intent_line = lines[0].strip() if not intent_line.startswith('!zw/'): raise ValueError(f"Invalid ZW format in {filename}") intent_type = intent_line.split('/')[1].split(':')[0] # Parse YAML body yaml_body = '\n'.join(lines[1:]) data = yaml.safe_load(yaml_body) return { 'intent_type': intent_type, 'data': data, 'source_file': filename } def get_voices_config(self): """Get voice mappings from voices.zw""" if 'voices' in self.configs: return self.configs['voices']['data'] return {} def get_emotions_config(self): """Get emotion mappings from emotions.zw""" if 'emotions' in self.configs: return self.configs['emotions']['data'] return {} def get_server_config(self): """Get server config from server.zw""" if 'server' in self.configs: return self.configs['server']['data'] return {} def generate_python_configs(self): """Generate Python config files from ZW files""" # Generate voices config voices = self.get_voices_config() if voices: voices_py = f"""# Generated from voices.zw CHARACTER_VOICES = {voices} """ with open('generated_voices.py', 'w') as f: f.write(voices_py) print("āœ… Generated: generated_voices.py") # Generate emotions config emotions = self.get_emotions_config() if emotions: emotions_py = f"""# Generated from emotions.zw EMOTION_PARAMETERS = {emotions} """ with open('generated_emotions.py', 'w') as f: f.write(emotions_py) print("āœ… Generated: generated_emotions.py") # Generate requirements.txt if 'requirements' in self.configs: req_data = self.configs['requirements']['data'] if 'packages' in req_data: with open('generated_requirements.txt', 'w') as f: for pkg in req_data['packages']: f.write(f"{pkg}\n") print("āœ… Generated: generated_requirements.txt") def main(): """Process all ZW files in current directory""" print("šŸ”§ ZW PROCESSOR - Reading your .zw files") print("=" * 50) processor = ZWProcessor() configs = processor.load_all_zw_files() if not configs: print("āŒ No .zw files found!") print("\nExpected files:") print(" - voices.zw") print(" - emotions.zw") print(" - server.zw") print(" - requirements.zw") return print(f"\nšŸ“Š Loaded {len(configs)} ZW configs:") for name, config in configs.items(): print(f" - {name}: {config['intent_type']}") # Generate Python configs print(f"\nšŸ­ Generating Python configs...") processor.generate_python_configs() # Show what's available print(f"\nšŸŽÆ Available configs:") print(f" - Voices: {len(processor.get_voices_config())} characters") print(f" - Emotions: {len(processor.get_emotions_config())} emotions") print(f" - Server: {bool(processor.get_server_config())}") print(f"\nāœ… ZW files processed successfully!") print("Now you can import the generated configs in your Python code.") if __name__ == "__main__": main()