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

Update minimal mode for new Google formatting #637

Merged
merged 9 commits into from
Feb 2, 2022
Merged
8 changes: 7 additions & 1 deletion app/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from urllib.parse import parse_qs
import os

minimal_mode_sections = ['Top stories', 'Images', 'People also ask']


def extract_q(q_str: str, href: str) -> str:
"""Extracts the 'q' element from a result link. This is typically
Expand Down Expand Up @@ -169,7 +171,11 @@ def pull_child_divs(result_div: BeautifulSoup):
for result in self.main_divs:
result_children = pull_child_divs(result)
if minimal_mode:
if len(result_children) in (1, 3):
if any(f">{x}</span" in str(s) for s in result_children
for x in minimal_mode_sections):
result.decompose()
continue
if len(result_children) < self.RESULT_CHILD_LIMIT:
continue
else:
if len(result_children) < self.RESULT_CHILD_LIMIT:
Expand Down