mirror of https://gitlab.com/bashrc2/epicyon
Allow non book paths for reading status
parent
c43f9ce74c
commit
f27cc4d66e
|
@ -25,18 +25,15 @@ from utils import date_from_string_format
|
||||||
def get_book_link_from_content(content: str) -> str:
|
def get_book_link_from_content(content: str) -> str:
|
||||||
""" Returns a book link from the given content
|
""" Returns a book link from the given content
|
||||||
"""
|
"""
|
||||||
if '/book/' not in content or \
|
if '://' not in content or \
|
||||||
'://' not in content or \
|
|
||||||
'"' not in content:
|
'"' not in content:
|
||||||
return None
|
return None
|
||||||
sections = content.split('/book/')
|
sections = content.split('://')
|
||||||
if '"' not in sections[0] or '"' not in sections[1]:
|
if '"' not in sections[0] or '"' not in sections[1]:
|
||||||
return None
|
return None
|
||||||
previous_str = sections[0].split('"')[-1]
|
previous_str = sections[0].split('"')[-1]
|
||||||
if '://' not in previous_str:
|
|
||||||
return None
|
|
||||||
next_str = sections[1].split('"')[0]
|
next_str = sections[1].split('"')[0]
|
||||||
book_url = previous_str + '/book/' + next_str
|
book_url = previous_str + '://' + next_str
|
||||||
return book_url
|
return book_url
|
||||||
|
|
||||||
|
|
||||||
|
|
9
tests.py
9
tests.py
|
@ -8252,6 +8252,12 @@ def _test_book_link(base_dir: str):
|
||||||
result = get_book_link_from_content(content)
|
result = get_book_link_from_content(content)
|
||||||
assert result == book_url
|
assert result == book_url
|
||||||
|
|
||||||
|
book_url = 'https://bookwyrm.instance/user/hj/1234567'
|
||||||
|
content = 'xyz wants to read <a ' + \
|
||||||
|
'href="' + book_url + '"><i>Title</i></a>'
|
||||||
|
result = get_book_link_from_content(content)
|
||||||
|
assert result == book_url
|
||||||
|
|
||||||
book_url = 'bookwyrm.instance/book/1234567'
|
book_url = 'bookwyrm.instance/book/1234567'
|
||||||
content = 'xyz wants to read <a ' + \
|
content = 'xyz wants to read <a ' + \
|
||||||
'href="' + book_url + '"><i>Title</i></a>'
|
'href="' + book_url + '"><i>Title</i></a>'
|
||||||
|
@ -8259,8 +8265,7 @@ def _test_book_link(base_dir: str):
|
||||||
assert result is None
|
assert result is None
|
||||||
|
|
||||||
book_url = 'https://bookwyrm.instance/other/1234567'
|
book_url = 'https://bookwyrm.instance/other/1234567'
|
||||||
content = 'xyz wants to read <a ' + \
|
content = 'xyz wants to read ' + book_url + '"><i>Title</i></a>'
|
||||||
'href="' + book_url + '"><i>Title</i></a>'
|
|
||||||
result = get_book_link_from_content(content)
|
result = get_book_link_from_content(content)
|
||||||
assert result is None
|
assert result is None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue