-
Notifications
You must be signed in to change notification settings - Fork 6
/
pre-process-seed.py
68 lines (52 loc) · 1.96 KB
/
pre-process-seed.py
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
"""
This script contains utility functions for pre-processing seed data for the Onboarder project.
Functions:
load_env(file_path='.env'):
Load environment variables from a specified file.
Parameters:
file_path (str): The path to the environment file. Defaults to '.env'.
Returns:
dict: A dictionary containing the environment variables as key-value pairs.
Raises:
FileNotFoundError: If the specified file is not found, a warning is printed and an empty dictionary is returned.
"""
import os
import shutil
def load_env(file_path='.env'):
"""Load environment variables from a file."""
env_vars = {}
try:
with open(file_path, 'r') as file:
for line in file:
line = line.strip()
if line and not line.startswith('#'):
key, value = line.split('=', 1)
env_vars[key.strip()] = value.strip().strip("'").strip('"')
except FileNotFoundError:
print(f"Warning: {
file_path} not found. Proceeding with system environment variables.")
return env_vars
# Load environment variables
env_vars = load_env()
# Define file paths
template_path = 'supabase/seed.sql.template'
output_path = 'supabase/seed.sql'
# Get the email from environment variables
email = env_vars.get("DEV_EMAIL")
# Check if the email is set
if email is None:
print("Error: DEV_EMAIL is not set in .env file or system environment variables")
exit(1)
# Copy template to new file
shutil.copy(template_path, output_path)
# Read the content of the new file
with open(output_path, 'r') as file:
content = file.read()
# Replace placeholders with environment variables
content = content.replace('DEV_EMAIL', email)
# Write the updated content back to the file
with open(output_path, 'w') as file:
file.write(content)
print(f"Generated {output_path} from {
template_path} with environment variables")
print(f"Using email: {email}")