Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: date and author tags #30

Merged
merged 1 commit into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .coverage
Binary file not shown.
39 changes: 6 additions & 33 deletions src/urban.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def get_statistics_from_soup(_soup: BeautifulSoup):
)


def get_date_from_soup(_soup: BeautifulSoup) -> str | None:
def get_author_and_date_from_soup(_soup: BeautifulSoup) -> str | None:
"""Return date from soup.

Parameters:
Expand All @@ -517,29 +517,7 @@ def get_date_from_soup(_soup: BeautifulSoup) -> str | None:
author_and_date = container.find_next("div", class_="contributor")

if author_and_date != None:
return (author_and_date.text).split(" ", 2)[2]


def get_author_from_soup(_soup: BeautifulSoup) -> str:
"""Return author from soup.

Parameters:
_soup: `_soup` object as `BeautifulSoup` object.

Return:
author as a string
"""

# get definition container
container: ResultSet[Tag] = derive_definition_as_tag(_soup) # pyright: ignore

return (
container.find_next("div", class_="contributor") # pyright: ignore
.find_next("a")["href"]
.split("=")[1]
.replace("%20", " ", -1)
)

return author_and_date.text.split(" ", " ".count(author_and_date.text))[0][3:]

def fetch_word_from_remote(_word: str) -> dict[str, str | None] | None:
"""Query urban dictionary for `_word`.
Expand Down Expand Up @@ -600,17 +578,13 @@ def fetch_word_from_remote(_word: str) -> dict[str, str | None] | None:
else:
words_as_str = insert_space_after_chars(list(words_as_str))

# Return definition, author, date all as dict
post_author = get_author_from_soup(_soup)

post_date = get_date_from_soup(_soup)
post_author_and_date = get_author_and_date_from_soup(_soup)

# TODO/FIXME return date as well
return {
"definition": words_as_str,
"example": example_as_str,
"author": post_author,
"date": post_date,
"author_and_date": post_author_and_date,
}


Expand Down Expand Up @@ -693,15 +667,14 @@ def main():
"Invalid type getting returned. Should be dictionary (function=main())"
)

# NOTE _ = `date`
definition, example, author, date = return_dict.values()
definition, example, author_and_date = return_dict.values()

rich_print(f"[bold]{word}: [/bold]", end="")
print(definition, end="\n\n")

print(colorama.Style.BRIGHT + f"{example}" + colorama.Style.RESET_ALL)

rich_print(f"\n[bold]by [italic]{author}[/italic][/bold] [white]{date}[/white]")
rich_print(f"\n[bold][white]by {author_and_date}[/white][/bold]")

raise SystemExit

Expand Down
16 changes: 0 additions & 16 deletions tests/test_unit_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
assert_soup_and_index_valid,
deinit_sys_exit,
display_requests_error,
get_date_from_soup,
get_found_word_from_soup,
get_soup_object_from_word,
insert_newline_for_break_tags,
Expand Down Expand Up @@ -183,18 +182,3 @@ def test_main_function(self):
"""
with self.assertRaises(SystemExit):
main()

def test_get_date(self):
"""
test get author function
"""

self.assertIsInstance(get_date_from_soup(self.soup), str) # pyright: ignore

def test_date_type(self):
"""
Test date type raises type error
"""

with self.assertRaises(TypeError):
get_date_from_soup("test") # pyright: ignore