sync simplification

- drop token compilation to html
- drop artlebedev typograph
- drop other small things
This commit is contained in:
tmshv committed 2020-03-21 20:02:59 +03:00
1 parent 5f51a6e00d
commit c1a3af3a3e
13 files changed
+73 -443

No files matched your search

-42
View File
@@ -1,5 +1,4 @@
from kazimir.Token import parse_file, is_document, Token
import math
class DocumentToken(Token):
@@ -16,44 +15,3 @@ class DocumentToken(Token):
data = parse_file(self.data)
document = await self.build(data)
return document
async def compile(self):
document = await self.get_data()
return create_document(document)
def create_document(document):
file_size = get_size(document['file_size'], 1)
file_format = 'ПДФ'
return f'''
<div>
<div class="document-row">
<a href="{document['url']}" class="invisible">
<div class="document-row__image">
<img src="{document['image_url']}" alt="{document['title']}">
</div>
</a>
<div class="document-row__file">
<a href="{document['url']}">{document['title']}</a>
</div>
<div class="document-row__file-info">
<a href="{document['file_url']}" target="_blank">
{file_format} ({file_size})
</a>
</div>
</div>
</div>
'''.strip()
def get_size(number_of_bytes, precision=1):
units = ['байт', 'КБ', 'МБ', 'ГБ', 'ТБ', 'ПБ']
number = math.floor(math.log(number_of_bytes) / math.log(1024))
size = (number_of_bytes / math.pow(1024, math.floor(number)))
size = round(size, precision)
return f'{size} {units[number]}'