Skip to content
Closed
Show file tree
Hide file tree
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
63 changes: 63 additions & 0 deletions .gitattributes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
# Auto-detect text files and normalize line endings to LF on commit
* text=auto eol=lf

# Explicitly declare text files to ensure normalization
*.py text eol=lf
*.pyi text eol=lf
*.js text eol=lf
*.ts text eol=lf
*.json text eol=lf
*.toml text eol=lf
*.yaml text eol=lf
*.yml text eol=lf
*.md text eol=lf
*.txt text eol=lf
*.rst text eol=lf
*.csv text eol=lf
*.ini text eol=lf
*.cfg text eol=lf
*.conf text eol=lf

# Shell scripts must use LF
*.sh text eol=lf
*.bash text eol=lf
*.zsh text eol=lf

# Batch files need CRLF on Windows
*.bat text eol=crlf
*.cmd text eol=crlf
*.ps1 text eol=crlf

# Web files
*.html text eol=lf
*.css text eol=lf
*.scss text eol=lf
*.xml text eol=lf

# Config files
.gitattributes text eol=lf
.gitignore text eol=lf
.editorconfig text eol=lf
Dockerfile text eol=lf
Makefile text eol=lf
*.dockerfile text eol=lf

# Jupyter notebooks (JSON-based, but special handling)
*.ipynb text eol=lf

# Binary files - don't touch these
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.webp binary
*.pdf binary
*.zip binary
*.tar.gz binary
*.whl binary
*.pyc binary
*.pyo binary
*.so binary
*.dll binary
*.exe binary
5 changes: 4 additions & 1 deletion .gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,4 +6,7 @@ dist/
.DS_Store
*.json
substack_api.egg-info/
.coverage
.coverage
site/
.claude/
.devcontainer/
27 changes: 27 additions & 0 deletions README.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@ This library provides Python interfaces for interacting with Substack's unoffici
- Get user profile information and subscriptions
- Fetch post content and metadata
- Search for posts within newsletters
- Access publication subscriber chats and threads
- Access paywalled content **that you have written or paid for** with user-provided authentication

## Installation
Expand DownExpand Up@@ -169,6 +170,32 @@ new_handle = resolve_handle_redirect("oldhandle")
if new_handle:
print(f"Handle was renamed to: {new_handle}")
```

### Working with Chats

Access publication subscriber chats (requires authentication):

```python
from substack_api import Chat, SubstackAuth

# Set up authentication (required for chat access)
auth = SubstackAuth(cookies_path="cookies.json")

# Access a publication's chat using its publication ID
chat = Chat(4906951, auth=auth)

# Get recent threads
threads = chat.get_threads(limit=5)
for thread in threads:
print(f"Thread: {thread.body[:80]}...")
print(f" By: {thread.author['name']} on {thread.created_at}")
print(f" {thread.comment_count} messages")

# Get messages in thread
for msg in thread.get_messages():
print(f" [{msg.created_at}] {msg.author['name']}: {msg.body[:60]}...")
```

## Limitations

- This is an unofficial library and not endorsed by Substack
Expand Down
Loading