Fix invalid calculator widget path (#1064)

When starting whoogle from another directory, the path to the calculator
widget was previously invalid. It now specifies the path relative to the widget
loader file.
main
MoistCat 2023-09-13 16:13:21 -04:00 committed by GitHub
parent a35b1dabbc
commit 693ca3a9a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -1,5 +1,10 @@
from pathlib import Path
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
# root
BASE_DIR = Path(__file__).parent.parent.parent
def add_ip_card(html_soup: BeautifulSoup, ip: str) -> BeautifulSoup: def add_ip_card(html_soup: BeautifulSoup, ip: str) -> BeautifulSoup:
"""Adds the client's IP address to the search results """Adds the client's IP address to the search results
if query contains keywords if query contains keywords
@ -48,7 +53,8 @@ def add_calculator_card(html_soup: BeautifulSoup) -> BeautifulSoup:
""" """
main_div = html_soup.select_one('#main') main_div = html_soup.select_one('#main')
if main_div: if main_div:
widget_file = open('app/static/widgets/calculator.html') # absolute path
widget_file = open(BASE_DIR / 'app/static/widgets/calculator.html', encoding="utf8")
widget_tag = html_soup.new_tag('div') widget_tag = html_soup.new_tag('div')
widget_tag['class'] = 'ZINbbc xpd O9g5cc uUPGi' widget_tag['class'] = 'ZINbbc xpd O9g5cc uUPGi'
widget_tag['id'] = 'calculator-wrapper' widget_tag['id'] = 'calculator-wrapper'
@ -56,7 +62,7 @@ def add_calculator_card(html_soup: BeautifulSoup) -> BeautifulSoup:
calculator_text['class'] = 'kCrYT ip-address-div' calculator_text['class'] = 'kCrYT ip-address-div'
calculator_text.string = 'Calculator' calculator_text.string = 'Calculator'
calculator_widget = html_soup.new_tag('div') calculator_widget = html_soup.new_tag('div')
calculator_widget.append(BeautifulSoup(widget_file, 'html.parser')); calculator_widget.append(BeautifulSoup(widget_file, 'html.parser'))
calculator_widget['class'] = 'kCrYT ip-text-div' calculator_widget['class'] = 'kCrYT ip-text-div'
widget_tag.append(calculator_text) widget_tag.append(calculator_text)
widget_tag.append(calculator_widget) widget_tag.append(calculator_widget)