forked from LiveCarta/BookConverter
Wrote documentation for every func/class in .py
This commit is contained in:
@@ -1,10 +1,3 @@
|
||||
""" This is Main Abstract class for solving a task of a book conversion
|
||||
|
||||
Having an id of coming book, gets book from server, runs conversion.
|
||||
In parallel it updates status of a book conversion on admin panel.
|
||||
Finally sends result to server.
|
||||
Result is a json, JSON schema in book_schema.json
|
||||
"""
|
||||
import os
|
||||
import json
|
||||
import codecs
|
||||
@@ -17,6 +10,14 @@ from src.util.helpers import BookLogger, BookStatusWrapper
|
||||
|
||||
|
||||
class BookSolver:
|
||||
"""
|
||||
This is Main Abstract class for solving a task of a book conversion
|
||||
Having an id of coming book, gets book from server, runs conversion.
|
||||
In parallel it updates status of a book conversion on admin panel.
|
||||
Finally sends result to server.
|
||||
Result is a json, JSON schema in book_schema.json
|
||||
"""
|
||||
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
def __init__(self, book_id=0, access=None, main_logger=None):
|
||||
@@ -55,9 +56,7 @@ class BookSolver:
|
||||
self.file_path = pathlib.Path(file_path)
|
||||
|
||||
def get_book_file(self):
|
||||
"""
|
||||
Method for getting and saving book from server.
|
||||
"""
|
||||
""" Method for getting and saving book from server. """
|
||||
try:
|
||||
self.logger_object.log(f'Start receiving file from server. URL: {self.access.url}/doc-convert/{self.book_id}/file')
|
||||
content = self.access.get_book(self.book_id)
|
||||
@@ -92,6 +91,7 @@ class BookSolver:
|
||||
self.logger_object.log('Error has occurred while writing json file.' + str(exc), logging.ERROR)
|
||||
|
||||
def send_json_content_to_server(self, content: dict):
|
||||
""" Function sends json_content to site """
|
||||
try:
|
||||
self.access.send_book(self.book_id, content)
|
||||
self.logger_object.log(f'JSON data has been sent to server.')
|
||||
@@ -108,8 +108,10 @@ class BookSolver:
|
||||
return {}
|
||||
|
||||
def test_conversion(self):
|
||||
'''Function
|
||||
without sending to server'''
|
||||
"""
|
||||
Function
|
||||
- without sending to server
|
||||
"""
|
||||
self.logger_object.log('Beginning of the test.')
|
||||
folder_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
folder_path = os.path.join(folder_path, f'{self.book_type}')
|
||||
@@ -121,9 +123,11 @@ class BookSolver:
|
||||
self.logger_object.log('End of the test.')
|
||||
|
||||
def conversion(self):
|
||||
'''Function
|
||||
with downloading book from server
|
||||
with sending to server'''
|
||||
"""
|
||||
Function
|
||||
- with downloading book from server
|
||||
- with sending to server
|
||||
"""
|
||||
try:
|
||||
self.logger_object.log(f'Beginning of conversion from .{self.book_type} to .json.')
|
||||
self.get_book_file()
|
||||
@@ -140,9 +144,11 @@ class BookSolver:
|
||||
raise exc
|
||||
|
||||
def conversion_local(self):
|
||||
'''Function
|
||||
without downloading book from server (local)
|
||||
with sending to server'''
|
||||
"""
|
||||
Function
|
||||
- without downloading book from server (local)
|
||||
- with sending to server
|
||||
"""
|
||||
try:
|
||||
self.logger_object.log(f'Data has been downloaded from tmp.json file: {self.file_path}')
|
||||
with codecs.open('json/tmp.json', 'r', encoding='utf-8') as f_json:
|
||||
|
||||
Reference in New Issue
Block a user