Skip to content

Commit

Permalink
Allow setting username and api_key in Wikidot.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmiegit committed Mar 10, 2024
1 parent 93265a8 commit c68e2cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 10 additions & 7 deletions yellowstone/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ class Config:
sites_use_admin_members: list[str]
always_fetch_site: bool

def __init__(self, path: str) -> None:
@staticmethod
def from_file(path: str) -> "Config":
with open(path, "rb") as file:
logger.info("Reading configuration file from %s", path)
data = tomllib.load(file)

self.s3_bucket = data["s3"]["bucket"]
self.site_slugs = data["wikidot"]["sites"]
self.sites_use_tls = data["wikidot"]["use-tls"]
self.sites_use_admin_members = data["wikidot"]["use-admin-members-list"]
self.always_fetch_site = data["wikidot"]["always-fetch-site"]
return Config(
s3_bucket=data["s3"]["bucket"],
site_slugs=data["wikidot"]["sites"],
sites_use_tls=data["wikidot"]["use-tls"],
sites_use_admin_members=data["wikidot"]["use-admin-members-list"],
always_fetch_site=data["wikidot"]["always-fetch-site"],
)

@staticmethod
def parse_args() -> "Config":
Expand All @@ -39,7 +42,7 @@ def parse_args() -> "Config":
help="The path to the configuration file to use",
)
args = parser.parse_args()
return Config(args.config)
return Config.from_file(args.config)

def uses_tls(self, site_slug: str) -> bool:
return site_slug in self.sites_use_tls
Expand Down
6 changes: 3 additions & 3 deletions yellowstone/wikidot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class Wikidot:
config: Config
proxy: ServerProxy

def __init__(self, config) -> None:
username = getenv("WIKIDOT_USERNAME")
api_key = getenv("WIKIDOT_API_KEY")
def __init__(self, config, *, username=None, api_key=None) -> None:
username = username or getenv("WIKIDOT_USERNAME")
api_key = api_key or getenv("WIKIDOT_API_KEY")
self.config = config
self.proxy = ServerProxy(
f"https://{username}:{api_key}@www.wikidot.com/xml-rpc-api.php",
Expand Down

0 comments on commit c68e2cf

Please sign in to comment.