weread-client
v0.0.6
Published
A TypeScript client library for interacting with WeRead (微信读书) API to fetch your reading notes, highlights, and book information.
Readme
WeRead Client
A TypeScript client library for interacting with WeRead (微信读书) API to fetch your reading notes, highlights, and book information.
Features
- 📚 Fetch your WeRead notebooks and book collection
- 🔖 Retrieve highlights and bookmarks for specific books
- 🎯 TypeScript support with full type definitions
- 🚀 Simple and lightweight API
- 🔒 Cookie-based authentication support
Installation
npm install weread-client
# or
pnpm add weread-client
# or
yarn add weread-clientUsage
Basic Setup
import { WeReadClient } from 'weread-client';
// Create a client instance
const client = new WeReadClient();
// Or with custom headers (e.g., for authentication)
const client = new WeReadClient({
headers: {
'Cookie': 'your-weread-cookies-here'
}
});Get Your Notebooks
const notebooks = await client.getWeReadNotebooks();
if (notebooks.status === 200) {
console.log(`Total books: ${notebooks.data.totalBookCount}`);
notebooks.data.books.forEach(book => {
console.log(`📖 ${book.book.title} by ${book.book.author}`);
console.log(` Notes: ${book.noteCount}, Bookmarks: ${book.bookmarkCount}`);
});
}Get Highlights for a Book
const bookId = 'your-book-id';
const highlights = await client.getWeReadHighlight(bookId);
if (highlights.status === 200) {
console.log(`Book: ${highlights.data.book.title}`);
highlights.data.updated.forEach(highlight => {
console.log(`💡 "${highlight.markText}"`);
console.log(` Created: ${new Date(highlight.createTime * 1000).toLocaleDateString()}`);
});
}API Reference
WeReadClient
Constructor
new WeReadClient(options?: WeReadClientOptions)Options:
headers?: Record<string, string> - Custom headers to include in requests
Methods
getWeReadNotebooks()
Fetches your WeRead notebook collection.
Returns: Promise<{ status: number, data: { synckey: number, totalBookCount: number, noBookReviewCount: number, books: WeReadBook[] } }>
getWeReadHighlight(bookId: string)
Fetches highlights and bookmarks for a specific book.
Parameters:
bookId: string - The unique identifier of the book
Returns: Promise<{ status: number, data: WeReadHighlight }>
Types
WeReadBook
type WeReadBook = {
book: {
author: string;
cover: string;
title: string;
translator: string;
};
bookId: string;
bookmarkCount: number;
noteCount: number;
reviewCount: number;
}WeReadHighlight
type WeReadHighlight = {
book: WeReadBook['book'];
chapters: {
chapterUid: number;
title: string;
}[];
updated: {
bookId: string;
markText: string;
chapterUid: number;
createTime: number;
range: string;
}[];
}Authentication
To access your personal WeRead data, you'll need to provide authentication cookies. You can obtain these by:
- Opening WeRead in your browser
- Logging in to your account
- Opening browser developer tools
- Copying the
Cookieheader from any WeRead API request - Passing it to the client:
const client = new WeReadClient({
headers: {
'Cookie': 'your-cookies-here'
}
});Development
# Install dependencies
pnpm install
# Build the project
pnpm buildContributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Disclaimer
This is an unofficial client library for WeRead. Use it responsibly and in accordance with WeRead's terms of service.
