Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.
validate_email.py · 1.8 KB · 66 lines
| 1 | |
| 2 | #!/usr/bin/env python3 |
| 3 | """ |
| 4 | AI-Generated Service: validate-email |
| 5 | Description: Validate email addresses and check format compliance |
| 6 | Generated: 2025-09-19T16:21:11.091812 |
| 7 | """ |
| 8 | |
| 9 | from typing import Dict, Any, Optional |
| 10 | import json |
| 11 | import asyncio |
| 12 | from datetime import datetime |
| 13 | |
| 14 | # AI-Generated Implementation |
| 15 | async def validate_email(data: Dict[str, Any]) -> Dict[str, Any]: |
| 16 | """ |
| 17 | Validate email addresses and check format compliance |
| 18 | |
| 19 | Inputs: email, strict_mode |
| 20 | Outputs: is_valid, error_message, suggestions |
| 21 | """ |
| 22 | |
| 23 | try: |
| 24 | # Extract inputs |
| 25 | email = data.get('email', '') |
| 26 | strict_mode = data.get('strict_mode', None) |
| 27 | |
| 28 | # AI-Generated Business Logic |
| 29 | # Perform validation |
| 30 | errors = [] |
| 31 | warnings = [] |
| 32 | |
| 33 | # AI-generated validation rules |
| 34 | if 'email' in locals() and '@' not in str(email): |
| 35 | errors.append('Invalid email format') |
| 36 | |
| 37 | if 'phone' in locals() and len(str(phone).replace('-', '')) < 10: |
| 38 | warnings.append('Phone number may be incomplete') |
| 39 | |
| 40 | result = { |
| 41 | 'valid': len(errors) == 0, |
| 42 | 'errors': errors, |
| 43 | 'warnings': warnings |
| 44 | } |
| 45 | |
| 46 | # Return results |
| 47 | return { |
| 48 | "success": True, |
| 49 | "timestamp": datetime.now().isoformat(), |
| 50 | "data": result |
| 51 | } |
| 52 | |
| 53 | except Exception as e: |
| 54 | return { |
| 55 | "success": False, |
| 56 | "error": str(e), |
| 57 | "timestamp": datetime.now().isoformat() |
| 58 | } |
| 59 | |
| 60 | # Synchronous wrapper for compatibility |
| 61 | def validate_email_sync(data: Dict[str, Any]) -> Dict[str, Any]: |
| 62 | """Synchronous wrapper for the async function""" |
| 63 | return asyncio.run(validate_email(data)) |
| 64 | |
| 65 | # Export the service |
| 66 | __all__ = ['validate_email', 'validate_email_sync'] |