Skip to content

Commit 554216d

Browse files
committed
fixed pylint errors
1 parent 266d372 commit 554216d

File tree

5 files changed

+55
-7
lines changed

5 files changed

+55
-7
lines changed

Diff for: README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Wiki cli searcher
2+
3+
Right now it is only able to search in Wikipedia. Techichally can search in every MediaWiki website (api to be added)
4+
5+
Works by requesting generated page contents, filtering them, converting them to Markdown and then displaying them.
6+
7+
## Usage
8+
9+
```bash
10+
python3 wiki <keyword>
11+
```
12+
13+
## Example
14+
15+
![tool screenshot](imgs/screenshot.png)

Diff for: wiki_search/__main__.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import argparse
2+
import logging as log
3+
import sys
4+
25
from bs4 import BeautifulSoup
36
from markdownify import MarkdownConverter
47
from rich.console import Console
58
from rich.markdown import Markdown
6-
from soup_filters import filter_soup
7-
from wikipedia import NoArticleFound, fetch_wiki_data
8-
from options import Options
9-
import logging as log
9+
10+
from .options import Options
11+
from .soup_filters import filter_soup
12+
from .wikipedia import NoArticleFound, fetch_wiki_data
1013

1114
log.basicConfig(level=log.INFO)
1215

@@ -26,7 +29,7 @@
2629
page_info = fetch_wiki_data(options, args.keyword)
2730
except NoArticleFound as e:
2831
console.print(f'No article "{e.fprompt}" found')
29-
exit(1)
32+
sys.exit(1)
3033

3134
soup = BeautifulSoup(page_info["text"]["*"], "html.parser")
3235

Diff for: wiki_search/options.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
"""Wikipedia search options module"""
12
from dataclasses import dataclass
23

34

45
@dataclass
56
class Options:
7+
"""Wikipedia search options class"""
8+
69
class_prefix: str = "en"
710
skip_tables: bool = True

Diff for: wiki_search/soup_filters.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
"""A bs4 filtering module."""
12
from bs4 import BeautifulSoup
2-
from options import Options
3+
4+
from .options import Options
35

46

57
def filter_soup(opts: Options, title: str, soup: BeautifulSoup) -> BeautifulSoup:
8+
"""Apply filtering to the soup.
9+
10+
:param opts: Request options.
11+
:type opts: Options
12+
:param title: Title of the article.
13+
:type title: str
14+
:param soup: BeautifoulSoup to filter.
15+
:type soup: BeautifulSoup
16+
:return: Filtered BeautifulSoup.
17+
:rtype: BeautifulSoup
18+
"""
619
body = soup.find("div", class_="mw-parser-output")
720
for tag in body.find_all("table", class_="infobox"):
821
tag.decompose()

Diff for: wiki_search/wikipedia.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1+
"""Wikipedia api request module."""
12
import requests
2-
from options import Options
3+
4+
from .options import Options
35

46

57
class NoArticleFound(Exception):
8+
"""No found article exception class."""
9+
610
def __init__(self, failed_prompt: str):
711
self.fprompt = failed_prompt
812

913

1014
def fetch_wiki_data(opts: Options, prompt: str) -> str:
15+
"""Fetch data html from Wiki api
16+
17+
:param opts: Request options.
18+
:type opts: Options
19+
:param prompt: Prompt to search at Wikipedia.
20+
:type prompt: str
21+
:raises NoArticleFound: Raised if no article found at Wikipedia.
22+
:return: String of HTML returned by API
23+
:rtype: str
24+
"""
1125
url = f"https://{opts.class_prefix}.wikipedia.org/w/api.php"
1226
params = {
1327
"action": "parse",

0 commit comments

Comments
 (0)