Skip to content

Commit

Permalink
fix: show better progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhd1701 committed May 25, 2022
1 parent ca823e0 commit cb7699e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
10 changes: 8 additions & 2 deletions enex2notion/enex_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@
from notion.block import CollectionViewPageBlock, PageBlock
from notion.collection import CollectionRowBlock
from notion.operations import build_operation
from progress.bar import Bar
from requests import HTTPError
from tqdm import tqdm

from enex2notion.enex_types import EvernoteNote
from enex2notion.enex_uploader_block import upload_block
from enex2notion.utils_exceptions import NoteUploadFailException

logger = logging.getLogger(__name__)

PROGRESS_BAR_WIDTH = 80


def upload_note(root, note: EvernoteNote, note_blocks):
logger.debug(f"Creating new page for note '{note.title}'")
new_page = _make_page(note, root)

progress_iter = tqdm(
iterable=note_blocks, unit="block", leave=False, ncols=PROGRESS_BAR_WIDTH
)

try:
for block in Bar().iter(note_blocks):
for block in progress_iter:
upload_block(new_page, block)
except HTTPError:
if isinstance(new_page, CollectionRowBlock):
Expand Down
36 changes: 23 additions & 13 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ enex2notion = "enex2notion.cli:main"
python = "^3.7"
beautifulsoup4 = "^4.11.1"
python-dateutil = "^2.8.2"
progress = "^1.6"
requests = "^2.27.1"
w3lib = "^1.22.0"
tinycss2 = "^1.1.1"
pdfkit = "^1.0.0"
PyMuPDF = "^1.19.6"
notion-vzhd1701-fork = "0.0.30"
tqdm = "^4.64.0"

[tool.poetry.dev-dependencies]
pytest = "^7.1.2"
Expand Down

0 comments on commit cb7699e

Please sign in to comment.