This repository has been archived on 2025-01-08. You can view files and clone it, but cannot push or open issues or pull requests.
blog-software/article.py

36 lines
760 B
Python
Raw Normal View History

2024-05-19 10:26:52 +02:00
from dataclasses import dataclass
from io import TextIOWrapper
2024-05-23 16:16:02 +02:00
from json import loads
2024-05-19 10:26:52 +02:00
from os import sep
@dataclass
class Article:
id: str
title: str
summary: str
content: str
2024-05-23 16:16:02 +02:00
@staticmethod
def from_open_file(file: TextIOWrapper) -> "Article":
id = file.name.split(sep)[-1].split('.')[0]
title = file.readline().strip()
summary = file.readline().strip()
content = file.read().strip()
2024-05-19 10:26:52 +02:00
2024-05-23 16:16:02 +02:00
return Article(id, title, summary, content)
2024-05-21 17:43:53 +02:00
@dataclass
2024-05-22 14:42:05 +02:00
class Site:
2024-05-21 17:43:53 +02:00
name: str
url: str
2024-05-23 16:16:02 +02:00
@staticmethod
def from_open_file(file: TextIOWrapper) -> "Site":
data = file.read()
data = loads(data)
return Site(
data['name'],
data['url']
)
2024-05-21 17:43:53 +02:00