Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# обновление сборки Docker-контейнера
build:
docker compose build

# генерация документации
docs-html:
docker compose run --workdir /docs app /bin/bash -c "make html"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Console application for creating a bibliography list.
The application allows you to automate the process of generating a bibliography list according to the specified citation standard.

Supported citation styles:
- ГОСТ Р 7.0.5-2008
- ГОСТ Р 7.0.5-2008
- Modern Language Association 9th edition

## Installation

Expand Down
5 changes: 3 additions & 2 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

Поддерживаемые стили цитирования:
- ГОСТ Р 7.0.5-2008
- Modern Language Association 9th edition

Установка
=========
Expand Down Expand Up @@ -85,8 +86,8 @@

docker compose run app python main.py

Запустится программа. Она считает исходный файл `media/input.xlsx`, выполнит обработку данных и сгенерирует выходной файл – `media/output.docx`.
Откройте этот файл и проверьте результат работы приложения.
Запустится программа. Она считает исходный файл `media/input.xlsx`, выполнит обработку данных и сгенерирует выходные файлы – `media/output_gost.docx` и media/output_mla.docx`.
Откройте эти файлы и проверьте результат работы приложения.

.. note::

Expand Down
Binary file modified media/template.xlsx
Binary file not shown.
4 changes: 2 additions & 2 deletions src/formatters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Базовые функции форматирования списка источников
"""

from formatters.styles.base import BaseCitationStyle
from logger import get_logger
from src.formatters.styles.base import BaseCitationStyle
from src.logger import get_logger


logger = get_logger(__name__)
Expand Down
103 changes: 102 additions & 1 deletion src/formatters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class InternetResourceModel(BaseModel):


class ArticlesCollectionModel(BaseModel):

"""
Модель сборника статей:

Expand All @@ -78,3 +77,105 @@ class ArticlesCollectionModel(BaseModel):
publishing_house: str
year: int = Field(..., gt=0)
pages: str


class ArticleMagazineModel(BaseModel):
"""
Модель статьи из журнала:

.. code-block::

ArticleMagazineModel(
authors="Иванов И.М., Петров С.Н.",
article_title="Наука как искусство",
magazine_title="Сборник научных трудов,
year=2020,
number=10,
pages="25-30",
)
"""

authors: str
article_title: str
magazine_title: str
year: int = Field(..., gt=0)
number: int = Field(..., gt=0)
pages: str


class LawModel(BaseModel):
"""
Модель закона, нормативного актa и т.п.:

.. code-block::

LawModel(
type="Конституция Российской Федерации",
law_title="Наука как искусство",
passing_date="01.01.2000",
number="1234-56",
source="Парламентская газета",
source_year=2020,
source_number=5,
article_number=15,
start_date="11.09.2002",
)
"""

type: str
law_title: str
passing_date: str
number: str
source: str
source_year: int = Field(..., gt=0)
source_number: int = Field(..., gt=0)
article_number: int = Field(..., gt=0)
start_date: str


class MLABookModel(BaseModel):
"""
Модель книги MLA:

.. code-block::

MLABookModel(
author_last_name="Smith",
author_first_name="Thomas",
title="The Citation Manual for Students: A Quick Guide",
edition="2nd",
publisher="Wiley",
year=2020,
)
"""

author_last_name: str
author_first_name: str
title: str
edition: Optional[str]
publisher: str
year: int = Field(..., gt=0)


class MLAInternetResourceModel(BaseModel):
"""
Модель интернет ресурса MLA:

.. code-block::

MLAInternetResourceModel(
author_last_name="Smith",
author_first_name="Thomas",
title="Whales Likely Impacted by Great Pacific Garbage Patch."
website="The Ocean Cleanup"
publication_date="10 Apr. 2019",
url="www.theoceancleanup.com/updates/whales-likely-impacted-by-great-pacific-garbage-patch",
)
"""

author_last_name: str
author_first_name: str
title: str
website: str
publication_date: str
url: str
69 changes: 62 additions & 7 deletions src/formatters/styles/gost.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

from pydantic import BaseModel

from formatters.models import BookModel, InternetResourceModel, ArticlesCollectionModel
from formatters.styles.base import BaseCitationStyle
from logger import get_logger

from src.formatters.models import BookModel, InternetResourceModel, ArticlesCollectionModel, ArticleMagazineModel, \
LawModel
from src.formatters.styles.base import BaseCitationStyle
from src.logger import get_logger

logger = get_logger(__name__)

Expand All @@ -27,7 +27,6 @@ def template(self) -> Template:
)

def substitute(self) -> str:

logger.info('Форматирование книги "%s" ...', self.data.title)

return self.template.substitute(
Expand Down Expand Up @@ -64,7 +63,6 @@ def template(self) -> Template:
)

def substitute(self) -> str:

logger.info('Форматирование интернет-ресурса "%s" ...', self.data.article)

return self.template.substitute(
Expand All @@ -89,7 +87,6 @@ def template(self) -> Template:
)

def substitute(self) -> str:

logger.info('Форматирование сборника статей "%s" ...', self.data.article_title)

return self.template.substitute(
Expand All @@ -103,6 +100,62 @@ def substitute(self) -> str:
)


class GOSTMagazineArticle(BaseCitationStyle):
"""
Форматирование для статьи из журнала.
"""

data: ArticleMagazineModel

@property
def template(self) -> Template:
return Template(
"$authors $article_title // $magazine_title. – $year. – №$number. – С. $pages."
)

def substitute(self) -> str:
logger.info('Форматирование статьи из журнала "%s" ...', self.data.article_title)

return self.template.substitute(
authors=self.data.authors,
article_title=self.data.article_title,
magazine_title=self.data.magazine_title,
year=self.data.year,
number=self.data.number,
pages=self.data.pages,
)


class GOSTLaw(BaseCitationStyle):
"""
Форматирование для закона, нормативного актa и т.п.
"""

data: LawModel

@property
def template(self) -> Template:
return Template(
"$type \"$law_title\" от $passing_date № $number // $source. - $source_year г. - № $source_number. - Ст. "
"$article_number с изм. и допол. в ред. от $start_date."
)

def substitute(self) -> str:
logger.info('Форматирование закона, нормативного актa и т.п. "%s" ...', self.data.law_title)

return self.template.substitute(
type=self.data.type,
law_title=self.data.law_title,
passing_date=self.data.passing_date,
number=self.data.number,
source=self.data.source,
source_year=self.data.source_year,
source_number=self.data.source_number,
article_number=self.data.article_number,
start_date=self.data.start_date,
)


class GOSTCitationFormatter:
"""
Базовый класс для итогового форматирования списка источников.
Expand All @@ -112,6 +165,8 @@ class GOSTCitationFormatter:
BookModel.__name__: GOSTBook,
InternetResourceModel.__name__: GOSTInternetResource,
ArticlesCollectionModel.__name__: GOSTCollectionArticle,
ArticleMagazineModel.__name__: GOSTMagazineArticle,
LawModel.__name__: GOSTLaw,
}

def __init__(self, models: list[BaseModel]) -> None:
Expand Down
106 changes: 106 additions & 0 deletions src/formatters/styles/mla.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
"""
Стиль цитирования по Modern Language Association 9th edition.
"""
from string import Template

from pydantic import BaseModel

from src.formatters.models import MLABookModel, MLAInternetResourceModel
from src.formatters.styles.base import BaseCitationStyle
from src.logger import get_logger

logger = get_logger(__name__)


class MLABook(BaseCitationStyle):
"""
Форматирование для книг.
"""

data: MLABookModel

@property
def template(self) -> Template:
return Template(
"$author_last_name, $author_first_name. $title. $edition$publisher, $year."
)

def substitute(self) -> str:
logger.info('Форматирование книги MLA "%s" ...', self.data.title)

return self.template.substitute(
author_last_name=self.data.author_last_name,
author_first_name=self.data.author_first_name,
title=self.data.title,
edition=self.get_edition(),
publisher=self.data.publisher,
year=self.data.year,
)

def get_edition(self) -> str:
"""
Получение отформатированной информации об издании.

:return: Информация об издании.
"""

return f"{self.data.edition} ed. " if self.data.edition else ""


class MLAInternetResource(BaseCitationStyle):
"""
Форматирование для интернет-ресурсов MLA.
"""

data: MLAInternetResourceModel

@property
def template(self) -> Template:
return Template(
"$author_last_name, $author_first_name. “$title” $website, $publication_date, $url."
)

def substitute(self) -> str:
logger.info('Форматирование интернет-ресурса MLA "%s" ...', self.data.title)

return self.template.substitute(
author_last_name=self.data.author_last_name,
author_first_name=self.data.author_first_name,
title=self.data.title,
website=self.data.website,
publication_date=self.data.publication_date,
url=self.data.url,
)


class MLACitationFormatter:
"""
Базовый класс для итогового форматирования списка источников.
"""

formatters_map = {
MLABookModel.__name__: MLABook,
MLAInternetResourceModel.__name__: MLAInternetResource
}

def __init__(self, models: list[BaseModel]) -> None:
"""
Конструктор.

:param models: Список объектов для форматирования
"""

formatted_items = []
for model in models:
formatted_items.append(self.formatters_map.get(type(model).__name__)(model)) # type: ignore

self.formatted_items = formatted_items

def format(self) -> list[BaseCitationStyle]:
"""
Форматирование списка источников.

:return:
"""

return sorted(self.formatted_items, key=lambda item: item.formatted)
2 changes: 1 addition & 1 deletion src/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
import logging

from settings import LOGGING_FORMAT, LOGGING_LEVEL, LOGGING_PATH
from src.settings import LOGGING_FORMAT, LOGGING_LEVEL, LOGGING_PATH


def get_logger(
Expand Down
Loading