-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.php
34 lines (30 loc) · 981 Bytes
/
env.php
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
#!/usr/bin/python3
"""
env.php
Example of handling .env file and get values from it.
The function can be included in other scripts like this:
from env import get_value
result = get_value()
"""
import os
from dotenv import load_dotenv
def get_value(argument_to_fetch, verbose=False):
"""
Function to fetch value from .env file based on argument_to_fetch
"""
try:
load_dotenv() #laddar.env
fetched_value = os.getenv(argument_to_fetch)
if fetched_value is None:
raise ValueError(f"Value for '{argument_to_fetch}' not found in .env file.")
return fetched_value
except Exception as e:
if verbose:
print(f"An error occurred while fetching value for '{argument_to_fetch}': {e}")
return None
## Start
if __name__ == "__main__":
argument_to_fetch = "SMTP_PORT"
result = get_value(argument_to_fetch)
print()
print(f" Fetched value for {argument_to_fetch}: {result}")