Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions substack/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import os
from datetime import datetime
from urllib.parse import urljoin

import requests

from requests.utils import cookiejar_from_dict
from substack.exceptions import SubstackAPIException, SubstackRequestException

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -64,8 +63,9 @@ def __init__(
# Load cookies from file if provided
# Helps with Captcha errors by reusing cookies from "local" auth, then switching to running code in the cloud
if cookies_path is not None:
with open(cookies_path) as f:
cookies = json.load(f)
with open(cookies_path, "r", encoding="utf-8") as f:
raw = json.load(f)
cookies = cookiejar_from_dict({c["name"]: c["value"] for c in raw})
self._session.cookies.update(cookies)

elif email is not None and password is not None:
Expand Down Expand Up @@ -189,11 +189,11 @@ def get_publication_url(publication: dict) -> str:
Args:
publication:
"""
custom_domain = publication["custom_domain"]
if not custom_domain:
publication_url = f"https://{publication['subdomain']}.substack.com"
else:
if publication.get('custom_domain_optional', None):
custom_domain = publication["custom_domain"]
publication_url = f"https://{custom_domain}"
else:
publication_url = f"https://{publication['subdomain']}.substack.com"

return publication_url

Expand Down