-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_usage.py
More file actions
79 lines (62 loc) · 2.27 KB
/
example_usage.py
File metadata and controls
79 lines (62 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
"""
Example usage of the SAS to Snowflake SQL Converter
This script demonstrates how to use the converter programmatically
without the CLI interface.
"""
import os
import logging
from convert import SASConverter
def load_env_file(env_path: str = '.env') -> None:
"""
Load environment variables from a .env file.
Args:
env_path (str): Path to the .env file (default: '.env')
"""
if os.path.exists(env_path):
with open(env_path, 'r') as file:
for line in file:
line = line.strip()
if line and not line.startswith('#') and '=' in line:
key, value = line.split('=', 1)
os.environ[key.strip()] = value.strip()
def main():
"""Example usage of the SAS converter."""
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Load .env file and get API key from environment
load_env_file()
api_key = os.getenv('GEMINI_API_KEY')
if not api_key:
logger.error("Please set GEMINI_API_KEY in environment variable or .env file")
return
# Initialize converter
converter = SASConverter(api_key)
# Example 1: Convert a single file
logger.info("Example 1: Converting a single file")
success = converter.convert_sas_file(
'sample_sas_files/example_data_step.sas',
'snowflake_output/example_data_step.sql'
)
if success:
logger.info("✅ Single file conversion successful")
else:
logger.error("❌ Single file conversion failed")
# Example 2: Convert all files in a folder
logger.info("Example 2: Converting all files in a folder")
results = converter.convert_sas_folder(
'sample_sas_files',
'snowflake_output'
)
if results:
successful = sum(1 for success in results.values() if success)
total = len(results)
logger.info(f"📊 Folder conversion: {successful}/{total} files successful")
for filename, success in results.items():
status = "✅" if success else "❌"
logger.info(f" {status} {filename}")
else:
logger.warning("No files were processed")
if __name__ == '__main__':
main()