Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Example script demonstrating how to use the AWS S3 storage utilities. | |
| """ | |
| import os | |
| from dotenv import load_dotenv | |
| from app.utils.aws_storage import AWSS3Storage | |
| def aws_storage_example(): | |
| """ | |
| Example of using the AWSS3Storage class to save and retrieve pitch data. | |
| """ | |
| # Load environment variables | |
| load_dotenv() | |
| # Check if AWS credentials are configured | |
| if not all([ | |
| os.getenv('AWS_ACCESS_KEY_ID'), | |
| os.getenv('AWS_SECRET_ACCESS_KEY'), | |
| os.getenv('AWS_S3_BUCKET_NAME') | |
| ]): | |
| print("AWS credentials not properly configured. Example will not work.") | |
| return | |
| # Initialize S3 storage | |
| s3_storage = AWSS3Storage() | |
| # Example pitch data | |
| example_script_id = f"example_pitch_{os.urandom(4).hex()}" | |
| example_elevator_pitch = "We're revolutionizing logistics with AI-powered optimization." | |
| example_full_pitch = """ | |
| Our company, LogiTech AI, is addressing the critical inefficiencies in global supply chains. | |
| The Problem: | |
| Current logistics solutions fail to adapt in real-time to changing conditions, resulting in delays, wasted resources, and environmental impact. | |
| Our Solution: | |
| Our platform uses machine learning to dynamically optimize shipping routes and packaging in real-time, responding to disruptions within minutes instead of hours. | |
| Market Opportunity: | |
| The global logistics optimization market is projected to reach $30B by 2026, growing at 16% CAGR. | |
| Traction: | |
| We've already partnered with 3 Fortune 500 retailers for pilot programs, reducing their shipping costs by an average of 23%. | |
| Team: | |
| Our founding team combines 25+ years of logistics experience with cutting-edge AI expertise from MIT and Stanford. | |
| We're seeking $2M in funding to scale our technology and expand our customer base in the e-commerce sector. | |
| """ | |
| # Example competitors and market insights | |
| example_competitors = """ | |
| ## Competitor Analysis | |
| ### OptimizeShip | |
| A logistics optimization platform focused on route planning. | |
| **Strengths:** | |
| - Strong route optimization algorithms | |
| - Established market presence | |
| **Weaknesses:** | |
| - Lacks real-time adaptation | |
| - No packaging optimization | |
| ### PackTech | |
| Specializes in packaging optimization for shipping. | |
| **Strengths:** | |
| - Deep expertise in packaging materials | |
| - Integration with major e-commerce platforms | |
| **Weaknesses:** | |
| - No route optimization capabilities | |
| - Limited AI implementation | |
| """ | |
| example_market_insights = """ | |
| ## Market Insights | |
| The logistics optimization market is experiencing rapid growth due to: | |
| 1. Increasing e-commerce sales globally | |
| 2. Rising shipping costs and supply chain disruptions | |
| 3. Growing emphasis on sustainability in shipping | |
| 4. Advancements in AI and machine learning technologies | |
| Major trends include: | |
| - Integration of IoT devices for real-time tracking | |
| - Demand for environmentally-friendly shipping solutions | |
| - Consolidation among logistics technology providers | |
| """ | |
| print("=== AWS S3 Storage Example ===") | |
| print(f"Using bucket: {s3_storage.bucket_name}") | |
| print(f"Example script ID: {example_script_id}") | |
| # Step 1: Save pitch data | |
| print("\n--- Step 1: Saving pitch data ---") | |
| save_result = s3_storage.save_pitch_data( | |
| script_id=example_script_id, | |
| elevator_pitch=example_elevator_pitch, | |
| full_pitch=example_full_pitch, | |
| competitors_data=example_competitors, | |
| market_insights=example_market_insights | |
| ) | |
| if save_result["success"]: | |
| print(f"β Successfully saved pitch data") | |
| print(f"S3 path: {save_result['s3_path']}") | |
| else: | |
| print(f"β Failed to save pitch data: {save_result['message']}") | |
| return | |
| # Step 2: Retrieve pitch data | |
| print("\n--- Step 2: Retrieving pitch data ---") | |
| retrieve_result = s3_storage.get_pitch_data(example_script_id) | |
| if retrieve_result["success"]: | |
| pitch_data = retrieve_result["data"] | |
| print("β Successfully retrieved pitch data") | |
| print(f"Retrieved script ID: {pitch_data['script_id']}") | |
| print(f"Created at: {pitch_data['created_at']}") | |
| print("\nElevator pitch preview:") | |
| print(f""{pitch_data['elevator_pitch']}"") | |
| else: | |
| print(f"β Failed to retrieve pitch data: {retrieve_result['message']}") | |
| # Step 3: List pitches | |
| print("\n--- Step 3: Listing pitches ---") | |
| list_result = s3_storage.list_pitches(limit=5) | |
| if list_result["success"]: | |
| pitches = list_result["pitches"] | |
| print(f"β Successfully listed pitches. Total count: {list_result['count']}") | |
| if list_result["count"] > 0: | |
| print("\nRecent pitches:") | |
| for i, pitch in enumerate(pitches[:5], 1): # Show up to 5 pitches | |
| print(f"{i}. {pitch['script_id']} (modified: {pitch['last_modified'].split('T')[0]})") | |
| else: | |
| print(f"β Failed to list pitches: {list_result['message']}") | |
| print("\n=== Example Complete ===") | |
| print(f"You can view this example pitch using the command:") | |
| print(f"python -m app.scripts_storage.get_pitch_details {example_script_id}") | |
| if __name__ == "__main__": | |
| aws_storage_example() |