forked from Instapaper/instaparser-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle.py
More file actions
56 lines (48 loc) · 1.76 KB
/
article.py
File metadata and controls
56 lines (48 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
Article class representing a parsed article from Instaparser.
"""
from dataclasses import dataclass, field
from typing import Any
@dataclass(repr=False)
class Article:
"""
Represents a parsed article from Instaparser.
Attributes:
url: The canonical URL of the article
title: The title of the article
site_name: The name of the website
author: The author's name
date: Published date as UNIX timestamp
description: Article description
thumbnail: Thumbnail image URL
words: Number of words in the article
is_rtl: Whether the article is right-to-left (Arabic/Hebrew)
images: List of images in the article
videos: List of embedded videos
body: The article body (HTML, text, or markdown depending on output format)
html: The HTML body (if output was 'html')
text: The plain text body (if output was 'text')
markdown: The markdown body (if output was 'markdown')
"""
url: str | None = None
title: str | None = None
site_name: str | None = None
author: str | None = None
date: Any | None = None
description: str | None = None
thumbnail: str | None = None
words: int = 0
is_rtl: bool = False
images: list[str] = field(default_factory=list)
videos: list[str] = field(default_factory=list)
html: str | None = None
text: str | None = None
markdown: str | None = None
@property
def body(self) -> str | None:
"""The article body (html if available, otherwise text, then markdown)."""
return self.html or self.text or self.markdown
def __repr__(self) -> str:
return f"<Article url={self.url!r} title={self.title!r}>"
def __str__(self) -> str:
return self.body or ""