-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add .env.example and dynamic project metadata extraction
- Loading branch information
Showing
6 changed files
with
94 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# === Configuration for MusicBrainz2Notion === # | ||
# This file contains environment variables needed to run the application. | ||
# Replace the placeholders with your actual values. Rename this file to `.env` | ||
# or export these variables into your environment. | ||
|
||
# === Notion API Token === # | ||
# The API token for accessing your Notion workspace. This token must be generated | ||
# by creating an integration in your Notion account and granting it the necessary permissions. | ||
# It has to be a Notion API token, not a token_v2 from a browser's cookie | ||
# Note: Keep this token secure and do not share it publicly. | ||
NOTION_TOKEN=secret_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | ||
|
||
# === Notion Database IDs === # | ||
# The IDs of the Notion databases used by the application. These IDs correspond | ||
# to the specific databases where information related to artists, releases, and recordings | ||
# will be stored or retrieved. | ||
# To Find the database id with the link of the database: | ||
# https://www.notion.so/<this_is_the_database_id>?v=<view_id>&pvs=4 | ||
|
||
# The ID for the database where artist information is stored/managed. | ||
ARTIST_DB_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | ||
|
||
# The ID for the database where release information is stored/managed. | ||
RELEASE_DB_ID=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy | ||
|
||
# The ID for the database where recording information is stored/managed. | ||
RECORDING_DB_ID=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz | ||
|
||
# Note: Ensure these database IDs match the databases in your Notion workspace | ||
# where the application is expected to read from or write to. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
"""About MusicBrainz2Notion.""" | ||
|
||
import pathlib | ||
import tomllib | ||
|
||
_PROJECT_ROOT = pathlib.Path(__file__).resolve().parent.parent.parent | ||
|
||
# Construct the path to pyproject.toml relative to the project root | ||
_PYPROJECT_PATH = _PROJECT_ROOT / "pyproject.toml" | ||
|
||
with _PYPROJECT_PATH.open("rb") as fp: | ||
_PYPROJECT_DATA = tomllib.load(fp) | ||
|
||
__version__ = "0.1.0" | ||
__app_name__ = _PYPROJECT_DATA["project"]["name"] | ||
__author__ = _PYPROJECT_DATA["project"]["authors"][0]["name"] | ||
__email__ = _PYPROJECT_DATA["project"]["authors"][0]["email"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,28 +2,43 @@ | |
|
||
import logging | ||
import os | ||
from enum import StrEnum | ||
|
||
import musicbrainzngs | ||
from dotenv import load_dotenv | ||
from loguru import logger | ||
from utils import InterceptHandler | ||
|
||
from musicbrainz2notion.__about__ import __app_name__, __email__, __version__ | ||
from musicbrainz2notion.utils import InterceptHandler | ||
|
||
|
||
# === Enums === # | ||
class EnvVar(StrEnum): | ||
"""Environment variable keys used in the application.""" | ||
|
||
NOTION_TOKEN = "NOTION_TOKEN" # noqa: S105 | ||
ARTIST_DB_ID = "ARTIST_DB_ID" | ||
RELEASE_DB_ID = "RELEASE_DB_ID" | ||
RECORDING_DB_ID = "RECORDING_DB_ID" | ||
|
||
|
||
# === Constants === # | ||
ARTIST_DB_ID = "" | ||
RELEASE_DB_ID = "" | ||
RECORDING_DB_ID = "" | ||
load_dotenv() | ||
# TODO: Add CLI for setting environment variables | ||
|
||
APP_NAME = "MusicBrainz2Notion" | ||
APP_VERSION = "0.0.1" | ||
APP_CONTACT = "[email protected]" | ||
ARTIST_DB_ID = os.getenv(EnvVar.ARTIST_DB_ID) | ||
RELEASE_DB_ID = os.getenv(EnvVar.RELEASE_DB_ID) | ||
RECORDING_DB_ID = os.getenv(EnvVar.RECORDING_DB_ID) | ||
|
||
MB_API_RATE_LIMIT_INTERVAL = 1 # Seconds | ||
MB_API_REQUEST_PER_INTERVAL = 10 | ||
|
||
NOTION_TOKEN = os.environ["NOTION_TOKEN"] # API token, no token_v2 from cookie | ||
NOTION_TOKEN = os.getenv(EnvVar.NOTION_TOKEN) | ||
|
||
# Set up logging with Loguru | ||
logging.basicConfig(handlers=[InterceptHandler()], level=0, force=True) | ||
|
||
|
||
musicbrainzngs.set_useragent(APP_NAME, APP_VERSION, APP_CONTACT) | ||
musicbrainzngs.set_useragent(__app_name__, __version__, __email__) | ||
musicbrainzngs.set_rate_limit(MB_API_RATE_LIMIT_INTERVAL, MB_API_REQUEST_PER_INTERVAL) | ||
logger.info("MusicBrainz client initialized.") |