1
0
Fork 0
mirror of https://github.com/Findus23/PaperLibrary-cli.git synced 2024-09-20 17:03:46 +02:00
PaperLibrary-cli/paperlibrary/api/models.py

96 lines
1.9 KiB
Python
Raw Normal View History

2020-10-14 21:38:36 +02:00
from dataclasses import dataclass, field
from datetime import datetime
from typing import Optional, List
2020-10-19 17:43:08 +02:00
from dataclasses_json import DataClassJsonMixin, config
2020-10-14 21:38:36 +02:00
from marshmallow import fields
@dataclass
class PDF(DataClassJsonMixin):
id: int
2020-11-01 13:48:40 +01:00
url: str
2020-10-14 21:38:36 +02:00
file: str
2020-11-01 13:48:40 +01:00
sha256: str
2020-10-14 21:38:36 +02:00
type: str
2020-11-01 13:48:40 +01:00
preview: Optional[str]
2020-10-14 21:38:36 +02:00
updated_at: datetime = field(
metadata=config(
encoder=datetime.isoformat,
decoder=datetime.fromisoformat,
mm_field=fields.DateTime(format='iso')
)
)
@dataclass
class Paper(DataClassJsonMixin):
2023-06-27 22:38:59 +02:00
id: int
2020-10-14 21:38:36 +02:00
url: str
title: str
2020-11-08 22:25:56 +01:00
custom_title: str
2020-10-14 21:38:36 +02:00
pdfs: List[PDF]
2020-11-01 13:48:40 +01:00
doi: Optional[str]
2020-10-14 21:38:36 +02:00
@property
2020-11-01 13:48:40 +01:00
def main_pdf(self) -> Optional[PDF]:
if not self.pdfs:
return None
2020-10-14 21:38:36 +02:00
return self.pdfs[0]
2020-11-01 13:48:40 +01:00
@dataclass
class PaperComplete(Paper):
keywords: List[str]
authors: List[str]
first_author: str
publication: str
doctype: str
2020-11-08 22:25:56 +01:00
arxiv_id: Optional[str]
2023-06-27 22:38:59 +02:00
arxiv_class: Optional[str]
ads_version: Optional[int]
2020-12-29 17:16:16 +01:00
bibcode: Optional[str]
2020-11-01 13:48:40 +01:00
year: int
pubdate: str # TODO: to datetime
entry_date: str # TODO: to datetime
2020-12-29 17:16:16 +01:00
citation_count: Optional[int]
2020-11-08 22:25:56 +01:00
citation_key: Optional[str]
recommended_by: List[str]
tags: List[str]
custom_title: str
2023-06-27 22:38:59 +02:00
notes_md: Optional[str]
notes_html: Optional[str]
notes_updated_at: Optional[str]
2020-11-01 13:48:40 +01:00
2020-10-14 21:38:36 +02:00
@dataclass
class Author(DataClassJsonMixin):
2023-06-27 22:38:59 +02:00
id: int
2020-10-14 21:38:36 +02:00
url: str
papers: List[Paper]
name: str
2020-11-01 13:48:40 +01:00
pretty_name: Optional[str]
2020-10-14 21:38:36 +02:00
affiliation: Optional[str]
orcid_id: Optional[str]
2020-10-19 17:43:08 +02:00
2020-11-01 13:48:40 +01:00
@property
def display_name(self):
return self.pretty_name if self.pretty_name else self.name
2020-10-19 17:43:08 +02:00
@dataclass
class Keyword(DataClassJsonMixin):
2023-06-27 22:38:59 +02:00
id: int
2020-10-19 17:43:08 +02:00
url: str
papers: List[Paper]
name: str
2020-11-01 13:48:40 +01:00
kw_schema: str
2023-06-27 22:38:59 +02:00
@dataclass
class Note(DataClassJsonMixin):
paper: int
text_md: str
text_html: str
updated_at: str