Skip to content
Open
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
5 changes: 5 additions & 0 deletions tests/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 14 additions & 1 deletion tree_plus_src/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = "",
Expand Down
Loading