Skip to content

Commit

Permalink
Fix apiparam #25 and wrong emojis #24
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Pletenev <[email protected]>
  • Loading branch information
ASMfreaK committed Apr 28, 2024
1 parent 14fff9c commit 430b8de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion habitipy/apidoc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@
@api {get} /api/v3/tasks/user Get a user's tasks
@apiName GetUserTasks
@apiGroup Task
@apiParam (Query) {String="habits","dailys","todos","rewards","completedTodos"} type Optional query parameter to return just a type of tasks. By default all types will be returned except completed todos that must be requested separately. The "completedTodos" type returns only the 30 most recently completed.
@apiParam (Query) {String="habits","dailys","todos","rewards","completedTodos"} [type] Optional query parameter to return just a type of tasks. By default all types will be returned except completed todos that must be requested separately. The "completedTodos" type returns only the 30 most recently completed.
@apiSuccess {Array} data An array of tasks
@apiSuccessExample
@apiError (BadRequest) Invalid_request_parameters Error returned if the type URL param was not correct.
Expand Down
29 changes: 22 additions & 7 deletions habitipy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from functools import partial
from textwrap import dedent
import re
from math import ceil
from typing import Tuple
# import logging
import pkg_resources
Expand All @@ -19,11 +20,17 @@
emojize = None # type: ignore


def progressed_bar(count, total=100, status=None, suffix=None, bar_len=10):
def progressed_bar(
count,
total=100, status=None, suffix=None,
width=None, bar_len=10):
"""render a progressed.io like progress bar"""
status = status or ''
suffix = suffix or '%'
assert isinstance(count, int)
max_width = 60 if status == '' else 90
width = max_width if width is None else width
bar_len = ceil(bar_len * width / max_width)
count_normalized = count if count <= total else total
filled_len = int(round(bar_len * count_normalized / float(total)))
percents = 100.0 * count / float(total)
Expand All @@ -45,12 +52,13 @@ def progressed_bar(count, total=100, status=None, suffix=None, bar_len=10):
_progressed_regex_str = r"""
!
\[[^]]*\]
\(\s*http://progressed\.io/bar/(?P<progress>[0-9]{1,3})
\(\s*(http://progressed\.io/bar|https://progress-bar.dev)/(?P<progress>[0-9]{1,3})/?
(
\?((
(title=(?P<title>[^&) "]*))|
(scale=(?P<scale>[^&) "]*))|
(suffix=(?P<suffix>[^&) "]*))
(title=(?P<title>[^&) "]*))
|(scale=(?P<scale>[^&) "]*))
|(suffix=(?P<suffix>[^&) "]*))
|(width=(?P<width>[^&) "]*))
)&*)*
){0,1}
\s*("[^"]*")*\)
Expand All @@ -61,11 +69,14 @@ def progressed_bar(count, total=100, status=None, suffix=None, bar_len=10):
def _progressed_match(m, bar_len=10):
progress = m['progress']
scale = m['scale']
width = m['width']
progress = int(progress) if progress is not None else 0
scale = int(scale) if scale is not None else 100
width = int(width) if width is not None else 100
return progressed_bar(
progress, total=scale,
status=m['title'], suffix=m['suffix'],
width=width,
bar_len=bar_len)


Expand Down Expand Up @@ -99,8 +110,12 @@ def prettify(string):
Write thesis πŸ“– β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ0%
```
"""
string = emojize(string, use_aliases=True) if emojize else string
string = progressed(string)
try:
string = emojize(string, language="alias") if emojize else string
string = progressed(string)
except Exception as error:
warnings.warn('Failed to prettify string: {}'.format(error))
pass
return string


Expand Down

0 comments on commit 430b8de

Please sign in to comment.