Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/betarixm/naver-blog.md
Convert NAVER blog posts to markdown files
https://github.com/betarixm/naver-blog.md
blog markdown naver naver-blog
Last synced: about 15 hours ago
JSON representation
Convert NAVER blog posts to markdown files
- Host: GitHub
- URL: https://github.com/betarixm/naver-blog.md
- Owner: betarixm
- Created: 2024-04-20T06:40:27.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-04-21T04:31:51.000Z (7 months ago)
- Last Synced: 2024-04-21T07:32:53.491Z (7 months ago)
- Topics: blog, markdown, naver, naver-blog
- Language: Python
- Homepage:
- Size: 43 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# naver-blog.md
Convert NAVER blog posts to markdown files.
## Installation
1. Clone the repository: `git clone https://github.com/betarixm/naver-blog.md.git`
2. Navigate to the project directory: `cd naver-blog.md`
3. Install dependencies: `poetry install`## Usage
### Basic Usage
```python
from naver_blog_md import (
with_default, # Use image sources without any modification,
with_fetched_local_images, # Fetch images into local directory while rendering
with_images_from_naver_cdn, # Use original images from Naver CDN
)
from naver_blog_md import use_blog, use_postblog_id = "YOUR-BLOG-ID"
(posts,) = use_blog(blog_id)
for post in posts():
metadata, as_markdown, _ = use_post(blog_id, post.log_no)
print(metadata())
print(as_markdown(**with_default()))```
### Download Images into Local Directory
```python
from pathlib import Path
from typing import Anyfrom naver_blog_md import (
use_blog,
use_post,
with_default, # Use image sources without any modification,
with_fetched_local_images, # Fetch images into local directory while rendering
with_images_from_naver_cdn, # Use original images from Naver CDN
)def crawl(blog_id: str, posts_directory: Path, assets_directory: Path):
(posts,) = use_blog(blog_id)for post in posts():
metadata, as_markdown, _ = use_post(
blog_id,
post.log_no,
)filename = to_filename(metadata())
post_assets_directory = assets_directory / filename
post_assets_directory.mkdir(exist_ok=True)render_context = with_fetched_local_images(
num_workers=64,
assets_directory=post_assets_directory,
image_src_prefix=f"assets/{filename}/",
)markdown = as_markdown(**render_context)
(posts_directory / filename).write_text(markdown)
def to_filename(metadata: dict[Any, Any]) -> str:
raise NotImplementedError()if __name__ == "__main__":
crawl("YOUR-BLOG-ID", Path("posts"), Path("assets"))
```