Merge remote-tracking branch 'origin/main' into heroku-app
This commit is contained in:
commit
7c3dbade09
|
@ -22,7 +22,7 @@ app.default_key = generate_user_key()
|
||||||
app.no_cookie_ips = []
|
app.no_cookie_ips = []
|
||||||
app.config['SECRET_KEY'] = os.urandom(32)
|
app.config['SECRET_KEY'] = os.urandom(32)
|
||||||
app.config['SESSION_TYPE'] = 'filesystem'
|
app.config['SESSION_TYPE'] = 'filesystem'
|
||||||
app.config['VERSION_NUMBER'] = '0.5.0'
|
app.config['VERSION_NUMBER'] = '0.5.1'
|
||||||
app.config['APP_ROOT'] = os.getenv(
|
app.config['APP_ROOT'] = os.getenv(
|
||||||
'APP_ROOT',
|
'APP_ROOT',
|
||||||
os.path.dirname(os.path.abspath(__file__)))
|
os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from app.request import VALID_PARAMS
|
from app.request import VALID_PARAMS, MAPS_URL
|
||||||
from app.utils.results import *
|
from app.utils.results import *
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from bs4.element import ResultSet, Tag
|
from bs4.element import ResultSet, Tag
|
||||||
|
@ -9,6 +9,19 @@ import urllib.parse as urlparse
|
||||||
from urllib.parse import parse_qs
|
from urllib.parse import parse_qs
|
||||||
|
|
||||||
|
|
||||||
|
def strip_blocked_sites(query: str) -> str:
|
||||||
|
"""Strips the blocked site list from the query, if one is being
|
||||||
|
used.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
query: The query string
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The query string without any "-site:..." filters
|
||||||
|
"""
|
||||||
|
return query[:query.find('-site:')] if '-site:' in query else query
|
||||||
|
|
||||||
|
|
||||||
class Filter:
|
class Filter:
|
||||||
def __init__(self, user_key: str, mobile=False, config=None) -> None:
|
def __init__(self, user_key: str, mobile=False, config=None) -> None:
|
||||||
if config is None:
|
if config is None:
|
||||||
|
@ -210,20 +223,20 @@ class Filter:
|
||||||
link['target'] = '_blank'
|
link['target'] = '_blank'
|
||||||
|
|
||||||
result_link = urlparse.urlparse(href)
|
result_link = urlparse.urlparse(href)
|
||||||
query_link = parse_qs(
|
query = parse_qs(
|
||||||
result_link.query
|
result_link.query
|
||||||
)['q'][0] if '?q=' in href else ''
|
)['q'][0] if 'q=' in href else ''
|
||||||
|
|
||||||
if query_link.startswith('/'):
|
if query.startswith('/'):
|
||||||
# Internal google links (i.e. mail, maps, etc) should still
|
# Internal google links (i.e. mail, maps, etc) should still
|
||||||
# be forwarded to Google
|
# be forwarded to Google
|
||||||
link['href'] = 'https://google.com' + query_link
|
link['href'] = 'https://google.com' + query
|
||||||
elif '/search?q=' in href:
|
elif '/search?q=' in href:
|
||||||
# "li:1" implies the query should be interpreted verbatim,
|
# "li:1" implies the query should be interpreted verbatim,
|
||||||
# which is accomplished by wrapping the query in double quotes
|
# which is accomplished by wrapping the query in double quotes
|
||||||
if 'li:1' in href:
|
if 'li:1' in href:
|
||||||
query_link = '"' + query_link + '"'
|
query = '"' + query + '"'
|
||||||
new_search = 'search?q=' + self.encrypt_path(query_link)
|
new_search = 'search?q=' + self.encrypt_path(query)
|
||||||
|
|
||||||
query_params = parse_qs(urlparse.urlparse(href).query)
|
query_params = parse_qs(urlparse.urlparse(href).query)
|
||||||
for param in VALID_PARAMS:
|
for param in VALID_PARAMS:
|
||||||
|
@ -234,13 +247,17 @@ class Filter:
|
||||||
link['href'] = new_search
|
link['href'] = new_search
|
||||||
elif 'url?q=' in href:
|
elif 'url?q=' in href:
|
||||||
# Strip unneeded arguments
|
# Strip unneeded arguments
|
||||||
link['href'] = filter_link_args(query_link)
|
link['href'] = filter_link_args(query)
|
||||||
|
|
||||||
# Add no-js option
|
# Add no-js option
|
||||||
if self.nojs:
|
if self.nojs:
|
||||||
append_nojs(link)
|
append_nojs(link)
|
||||||
else:
|
else:
|
||||||
link['href'] = href
|
if href.startswith(MAPS_URL):
|
||||||
|
# Maps links don't work if a site filter is applied
|
||||||
|
link['href'] = MAPS_URL + "?q=" + strip_blocked_sites(query)
|
||||||
|
else:
|
||||||
|
link['href'] = href
|
||||||
|
|
||||||
# Replace link location if "alts" config is enabled
|
# Replace link location if "alts" config is enabled
|
||||||
if self.alt_redirect:
|
if self.alt_redirect:
|
||||||
|
|
|
@ -10,6 +10,7 @@ from stem import Signal, SocketError
|
||||||
from stem.control import Controller
|
from stem.control import Controller
|
||||||
|
|
||||||
SEARCH_URL = 'https://www.google.com/search?gbv=1&q='
|
SEARCH_URL = 'https://www.google.com/search?gbv=1&q='
|
||||||
|
MAPS_URL = 'https://maps.google.com/maps'
|
||||||
AUTOCOMPLETE_URL = ('https://suggestqueries.google.com/'
|
AUTOCOMPLETE_URL = ('https://suggestqueries.google.com/'
|
||||||
'complete/search?client=toolbar&')
|
'complete/search?client=toolbar&')
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ from flask import jsonify, make_response, request, redirect, render_template, \
|
||||||
from requests import exceptions
|
from requests import exceptions
|
||||||
|
|
||||||
from app import app
|
from app import app
|
||||||
|
from app.filter import strip_blocked_sites
|
||||||
from app.models.config import Config
|
from app.models.config import Config
|
||||||
from app.request import Request, TorError
|
from app.request import Request, TorError
|
||||||
from app.utils.bangs import resolve_bang
|
from app.utils.bangs import resolve_bang
|
||||||
|
@ -247,7 +248,7 @@ def search():
|
||||||
'header.html',
|
'header.html',
|
||||||
config=g.user_config,
|
config=g.user_config,
|
||||||
logo=render_template('logo.html', dark=g.user_config.dark),
|
logo=render_template('logo.html', dark=g.user_config.dark),
|
||||||
query=urlparse.unquote(query),
|
query=strip_blocked_sites(urlparse.unquote(query)),
|
||||||
search_type=search_util.search_type,
|
search_type=search_util.search_type,
|
||||||
mobile=g.user_request.mobile)
|
mobile=g.user_request.mobile)
|
||||||
if 'isch' not in search_util.search_type else '')), resp_code
|
if 'isch' not in search_util.search_type else '')), resp_code
|
||||||
|
|
|
@ -54,5 +54,33 @@
|
||||||
"apply": "Aplicar",
|
"apply": "Aplicar",
|
||||||
"save-as": "Guardar como...",
|
"save-as": "Guardar como...",
|
||||||
"github-link": "Ver en GitHub"
|
"github-link": "Ver en GitHub"
|
||||||
|
},
|
||||||
|
"lang_it": {
|
||||||
|
"search": "Cerca",
|
||||||
|
"config": "Impostazioni",
|
||||||
|
"config-country": "Filtra risultati per paese",
|
||||||
|
"config-country-help": "Nota: se abilitato, il sito sarà presente tra i risultati se e soltanto se il server risiede nel paese selezionato",
|
||||||
|
"config-lang": "Lingua dell'interfaccia",
|
||||||
|
"config-lang-search": "Lingua della ricerca",
|
||||||
|
"config-near": "Vicino",
|
||||||
|
"config-near-help": "Nome della città",
|
||||||
|
"config-block": "Blocca",
|
||||||
|
"config-block-help": "Lista di siti separati da virgole",
|
||||||
|
"config-nojs": "Mostra link NoJS",
|
||||||
|
"config-dark": "Modalità Notte",
|
||||||
|
"config-safe": "Ricerca Sicura",
|
||||||
|
"config-alts": "Sostituisci link dei social",
|
||||||
|
"config-alts-help": "Sostituisci link di Twitter/YouTube/Instagram/etc con alternative che rispettano la privacy.",
|
||||||
|
"config-new-tab": "Apri i link in una nuova scheda",
|
||||||
|
"config-images": "Ricerca Immagini",
|
||||||
|
"config-images-help": "(Sperimentale) Aggiunge la modalità 'Ricerca Immagini'. Questo ridurrà drasticamente la qualità delle miniature durante la ricerca.",
|
||||||
|
"config-tor": "Usa Tor",
|
||||||
|
"config-get-only": "Utilizza solo richieste GET",
|
||||||
|
"config-url": "Root URL",
|
||||||
|
"config-css": "CSS Personalizzato",
|
||||||
|
"load": "Carica",
|
||||||
|
"apply": "Applica",
|
||||||
|
"save-as": "Salva Come...",
|
||||||
|
"github-link": "Guarda su GitHub"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
class="noHIxc"
|
class="noHIxc"
|
||||||
name="q"
|
name="q"
|
||||||
style="background-color: {{ 'var(--whoogle-dark-result-bg)' if config.dark else 'var(--whoogle-result-bg)' }} !important;
|
style="background-color: {{ 'var(--whoogle-dark-result-bg)' if config.dark else 'var(--whoogle-result-bg)' }} !important;
|
||||||
color: {{ 'var(--whoogle-dark-text)' if config.dark else 'var(--whoogle-text)' }};
|
color: {{ 'var(--whoogle-dark-text)' if config.dark else 'var(--whoogle-text)' }};"
|
||||||
type="text"
|
type="text"
|
||||||
value="{{ query[:query.find('-site:')] if '-site:' in query else query }}">
|
value="{{ query }}">
|
||||||
<input style="color: {{ 'var(--whoogle-dark-text)' if config.dark else 'var(--whoogle-text)' }}" id="search-reset" type="reset" value="x">
|
<input style="color: {{ 'var(--whoogle-dark-text)' if config.dark else 'var(--whoogle-text)' }}" id="search-reset" type="reset" value="x">
|
||||||
<input name="tbm" value="{{ search_type }}" style="display: none">
|
<input name="tbm" value="{{ search_type }}" style="display: none">
|
||||||
<input type="submit" style="display: none;">
|
<input type="submit" style="display: none;">
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
name="q"
|
name="q"
|
||||||
spellcheck="false"
|
spellcheck="false"
|
||||||
type="text"
|
type="text"
|
||||||
value="{{ query[:query.find('-site:')] if '-site:' in query else query }}"
|
value="{{ query }}"
|
||||||
style="background-color: {{ 'var(--whoogle-dark-result-bg)' if config.dark else 'var(--whoogle-result-bg)' }} !important;
|
style="background-color: {{ 'var(--whoogle-dark-result-bg)' if config.dark else 'var(--whoogle-result-bg)' }} !important;
|
||||||
color: {{ 'var(--whoogle-dark-text)' if config.dark else 'var(--whoogle-text)' }};
|
color: {{ 'var(--whoogle-dark-text)' if config.dark else 'var(--whoogle-text)' }};
|
||||||
border-bottom: {{ '2px solid var(--whoogle-dark-element-bg)' if config.dark else '0px' }};">
|
border-bottom: {{ '2px solid var(--whoogle-dark-element-bg)' if config.dark else '0px' }};">
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
from app.filter import Filter, get_first_link
|
import os
|
||||||
from app.request import gen_query
|
from typing import Any
|
||||||
|
|
||||||
from bs4 import BeautifulSoup as bsoup
|
from bs4 import BeautifulSoup as bsoup
|
||||||
from cryptography.fernet import Fernet, InvalidToken
|
from cryptography.fernet import Fernet, InvalidToken
|
||||||
from flask import g
|
from flask import g
|
||||||
from typing import Any, Tuple
|
|
||||||
import os
|
from app.filter import Filter, get_first_link
|
||||||
|
from app.request import gen_query
|
||||||
|
|
||||||
TOR_BANNER = '<hr><h1 style="text-align: center">You are using Tor</h1><hr>'
|
TOR_BANNER = '<hr><h1 style="text-align: center">You are using Tor</h1><hr>'
|
||||||
CAPTCHA = 'div class="g-recaptcha"'
|
CAPTCHA = 'div class="g-recaptcha"'
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -8,7 +8,7 @@ setuptools.setup(
|
||||||
author='Ben Busby',
|
author='Ben Busby',
|
||||||
author_email='benbusby@protonmail.com',
|
author_email='benbusby@protonmail.com',
|
||||||
name='whoogle-search',
|
name='whoogle-search',
|
||||||
version='0.5.0',
|
version='0.5.1',
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
install_requires=requirements,
|
install_requires=requirements,
|
||||||
description='Self-hosted, ad-free, privacy-respecting metasearch engine',
|
description='Self-hosted, ad-free, privacy-respecting metasearch engine',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user