mirror of https://github.com/Bunsly/JobSpy
added pydantic settings
parent
f83e875171
commit
fe3ee7c4d8
|
@ -6,7 +6,8 @@
|
|||
**/output/
|
||||
**/.DS_Store
|
||||
*.pyc
|
||||
.env
|
||||
src/config/.env.prod
|
||||
src/config/.env.dev
|
||||
dist
|
||||
jobs.csv
|
||||
.vscode/launch.json
|
||||
|
|
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
|
@ -0,0 +1,25 @@
|
|||
import os
|
||||
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
if not os.getenv("ENV"):
|
||||
raise ValueError("Invalid environment. Set the 'ENV' variable (e.g., export ENV=dev).")
|
||||
|
||||
dotenv_file = os.path.join(os.path.dirname(__file__), ".env." + os.environ.get("ENV"))
|
||||
|
||||
if not os.path.exists(dotenv_file):
|
||||
raise FileNotFoundError(f"Environment file not found: {dotenv_file}")
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
environment: str
|
||||
telegram_api_token: str
|
||||
mongo_uri: str
|
||||
mongo_db_name: str
|
||||
print(f"Loading environment from: {dotenv_file}")
|
||||
model_config = SettingsConfigDict(
|
||||
env_file=dotenv_file
|
||||
)
|
||||
|
||||
|
||||
settings = Settings()
|
|
@ -3,6 +3,7 @@ import os
|
|||
from pymongo import MongoClient
|
||||
from pymongo.synchronous.database import Database
|
||||
|
||||
from config.settings import settings
|
||||
from jobspy import create_logger
|
||||
|
||||
|
||||
|
@ -17,12 +18,12 @@ class MongoDB:
|
|||
self = super().__new__(cls)
|
||||
cls._instance = self
|
||||
logger = create_logger("Mongo Client")
|
||||
mongoUri = os.getenv("MONGO_URI")
|
||||
mongoUri = settings.mongo_uri
|
||||
if not mongoUri:
|
||||
logger.error("MONGO_URI environment variable is not set")
|
||||
raise ValueError("MONGO_URI environment variable is not set")
|
||||
client = MongoClient(mongoUri)
|
||||
database_name = os.getenv("MONGO_DB_NAME")
|
||||
database_name = settings.mongo_db_name
|
||||
if not database_name:
|
||||
logger.error("MONGO_DB_NAME environment variable is not set")
|
||||
raise ValueError(
|
||||
|
|
|
@ -5,6 +5,7 @@ from dotenv import load_dotenv
|
|||
from telegram import Bot, InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from telegram.constants import ReactionEmoji
|
||||
|
||||
from config.settings import settings
|
||||
from jobspy.jobs import JobPost
|
||||
from jobspy.scrapers.utils import create_logger
|
||||
|
||||
|
@ -20,7 +21,7 @@ class TelegramBot:
|
|||
return cls.instance
|
||||
|
||||
def __init__(self):
|
||||
self._api_token = os.getenv("TELEGRAM_API_TOKEN")
|
||||
self._api_token = settings.telegram_api_token
|
||||
self.bot = Bot(token=self._api_token)
|
||||
|
||||
def get_reply_markup(self):
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import os
|
||||
from dotenv import load_dotenv
|
||||
from db import JobRepository
|
||||
|
||||
from db.job_repository import JobRepository
|
||||
from tests.test_util import createMockJob
|
||||
|
||||
load_dotenv()
|
||||
|
@ -13,7 +13,7 @@ class DatabaseTests:
|
|||
This block ensures that the script runs the test only when executed directly,
|
||||
not when imported as a module.
|
||||
"""
|
||||
self.jobRepository = JobRepository(os.getenv("MONGO_DB_NAME") + "dev")
|
||||
self.jobRepository = JobRepository()
|
||||
|
||||
def insert_job(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue