Skip to content

Commit

Permalink
Namespace environment variables with RFTB_ prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
kdknigga committed Jul 18, 2024
1 parent 53c213e commit 8029966
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
12 changes: 6 additions & 6 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PRAW_CLIENT_ID=""
PRAW_CLIENT_SECRET=""
PRAW_USERNAME=""
PRAW_PASSWORD=""
SUBREDDIT=""
DB_CONNECTION_STRING="sqlite+aiosqlite:///:memory:"
RFTB_PRAW_CLIENT_ID=""
RFTB_PRAW_CLIENT_SECRET=""
RFTB_PRAW_USERNAME=""
RFTB_PRAW_PASSWORD=""
RFTB_SUBREDDIT=""
RFTB_DB_CONNECTION_STRING="sqlite+aiosqlite:///:memory:"
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ See https://redditclient.readthedocs.io/en/latest/oauth/ for details.

### 5. Set up secrets in environment variables
```
$ export PRAW_CLIENT_ID="your_client_id_here"
$ export PRAW_CLIENT_SECRET="your_client_secret_here"
$ export PRAW_USERNAME="your_reddit_username_here"
$ export PRAW_PASSWORD="your_reddit_password_here"
$ export SUBREDDIT="the_name_of_a_subreddit_here"
$ export RFTB_PRAW_CLIENT_ID="your_client_id_here"
$ export RFTB_PRAW_CLIENT_SECRET="your_client_secret_here"
$ export RFTB_PRAW_USERNAME="your_reddit_username_here"
$ export RFTB_PRAW_PASSWORD="your_reddit_password_here"
$ export RFTB_SUBREDDIT="the_name_of_a_subreddit_here"
```

or, put the secrets in a file called .env (see .env.example)
Expand Down
20 changes: 10 additions & 10 deletions rflying_tower_bot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def __init__(self, reddit: Reddit) -> None:
f"{__name__}.{self.__class__.__name__}"
)
self.reddit: Reddit = reddit
self.subreddit_name: str = os.getenv("SUBREDDIT", "flying")
self.subreddit_name: str = os.getenv("RFTB_SUBREDDIT", "flying")
self.rules_wiki_page = "botconfig/rflying_tower_bot"
self.rules: Ruleset | None = None
self.history = History(
os.getenv("DB_CONNECTION_STRING", "sqlite+aiosqlite:///:memory:")
os.getenv("RFTB_DB_CONNECTION_STRING", "sqlite+aiosqlite:///:memory:")
)

async def update_rules(self) -> None:
Expand Down Expand Up @@ -92,24 +92,24 @@ def __init__(self) -> None:
f"{__name__}.{self.__class__.__name__}"
)

self.client_id: str | None = os.getenv("PRAW_CLIENT_ID")
self.client_id: str | None = os.getenv("RFTB_PRAW_CLIENT_ID")
if self.client_id is None:
raise TypeError("Environment variable PRAW_CLIENT_ID is not set")
raise TypeError("Environment variable RFTB_PRAW_CLIENT_ID is not set")

self.client_secret: str | None = os.getenv("PRAW_CLIENT_SECRET")
self.client_secret: str | None = os.getenv("RFTB_PRAW_CLIENT_SECRET")
if self.client_secret is None:
raise TypeError("Environment variable PRAW_CLIENT_SECRET is not set")
raise TypeError("Environment variable RFTB_PRAW_CLIENT_SECRET is not set")

self.client_user_agent: str = os.getenv(
"PRAW_CLIENT_USER_AGENT",
"RFTB_PRAW_CLIENT_USER_AGENT",
f"Python/Linux:rFlyingTowerBot:{bot_version} (by /u/kdknigga)",
)

self.username: str = os.getenv("PRAW_USERNAME", "rFlyingTower")
self.username: str = os.getenv("RFTB_PRAW_USERNAME", "rFlyingTower")

self.password: str | None = os.getenv("PRAW_PASSWORD")
self.password: str | None = os.getenv("RFTB_PRAW_PASSWORD")
if self.client_secret is None:
raise TypeError("Environment variable PRAW_PASSWORD is not set")
raise TypeError("Environment variable RFTB_PRAW_PASSWORD is not set")


async def get_current_post_flair(subreddit: Subreddit) -> dict[str, PostFlairSettings]:
Expand Down

0 comments on commit 8029966

Please sign in to comment.