36 lines
No EOL
760 B
Python
36 lines
No EOL
760 B
Python
from dataclasses import dataclass
|
|
from io import TextIOWrapper
|
|
from json import loads
|
|
from os import sep
|
|
|
|
@dataclass
|
|
class Article:
|
|
id: str
|
|
title: str
|
|
summary: str
|
|
content: str
|
|
|
|
@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()
|
|
|
|
return Article(id, title, summary, content)
|
|
|
|
@dataclass
|
|
class Site:
|
|
name: str
|
|
url: str
|
|
|
|
@staticmethod
|
|
def from_open_file(file: TextIOWrapper) -> "Site":
|
|
data = file.read()
|
|
data = loads(data)
|
|
|
|
return Site(
|
|
data['name'],
|
|
data['url']
|
|
)
|
|
|