diff --git a/tests/test_web.py b/tests/test_web.py index 8236ef3..2119197 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -4,3 +4,8 @@ def test_articles_from_hacker_news(): articles = web.articles_from_hacker_news(max_depth=1, n_articles=1) assert bool(articles) + + +def test_create_link_wiki(): + link = web.create_link("wiki", "Stack Overflow") + assert "https://en.wikipedia.org/wiki/stack_overflow" in link diff --git a/tree_plus_src/web.py b/tree_plus_src/web.py index 7655e4e..6ae147b 100644 --- a/tree_plus_src/web.py +++ b/tree_plus_src/web.py @@ -44,7 +44,7 @@ def create_link(kind: Action, query: str) -> str: if kind == "search_wikipedia": link = create_wikipedia_search_link(query) elif kind == "wiki": - link = create_google_search_link(query) + link = create_wikipedia_link(query) elif kind == "search_google": link = create_stack_overflow_search_link(query) assert link is not None @@ -89,6 +89,19 @@ def create_wikipedia_search_link( return wikipedia_search_link +def create_wikipedia_link( + subterm: str, + prefix: str = "", + suffix: str = "", + link_style: str = LINK_STYLE, +) -> str: + wikipedia_url = create_wikipedia_url(subterm) + wikipedia_link = f"[{link_style}][link={wikipedia_url}]" + wikipedia_link += f"{prefix}{subterm}{suffix}" + wikipedia_link += f"[/link][/{link_style}]" + return wikipedia_link + + def create_google_search_link( subterm: str, prefix: str = "",