Spaces:
Running
Running
File size: 1,020 Bytes
54a110c 48ec86e 54a110c 48ec86e 4d96293 48ec86e 54a110c 48ec86e 54a110c |
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 |
"""Get gemini keys."""
import re
from pathlib import Path
import rich
import yaml
from dotenv import dotenv_values
from loguru import logger
def get_gemini_keys(file=r".env-gemini", dotenv=False):
"""Get gemini keys."""
if not Path(file).exists():
logger.debug(f"{file} does not exit, returning [] ")
return []
if Path(file).name.startswith(".env"):
dotenv = True
if isinstance(dotenv, bool) or isinstance(dotenv, float):
dotenv = bool(dotenv)
if dotenv is True:
try:
keys = yaml.load(dotenv_values(file).get("GEMINI_API_KEYS"), yaml.Loader)
except Exception as e:
logger.error(e)
return []
return keys
try:
text = Path(file).read_text()
# return re.findall(r"AIzaSy[A-Z][\w-]+", text)
return re.findall(r"AIzaSy[A-Z][\w-]{32}", text)
except Exception as e:
print(e)
return []
if __name__ == "__main__":
rich.get_console().print(get_gemini_keys())
|