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.config['SECRET_KEY'] = os.urandom(32)
|
||||
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_ROOT',
|
||||
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 bs4 import BeautifulSoup
|
||||
from bs4.element import ResultSet, Tag
|
||||
|
@ -9,6 +9,19 @@ import urllib.parse as urlparse
|
|||
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:
|
||||
def __init__(self, user_key: str, mobile=False, config=None) -> None:
|
||||
if config is None:
|
||||
|
@ -210,20 +223,20 @@ class Filter:
|
|||
link['target'] = '_blank'
|
||||
|
||||
result_link = urlparse.urlparse(href)
|
||||
query_link = parse_qs(
|
||||
query = parse_qs(
|
||||
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
|
||||
# be forwarded to Google
|
||||
link['href'] = 'https://google.com' + query_link
|
||||
link['href'] = 'https://google.com' + query
|
||||
elif '/search?q=' in href:
|
||||
# "li:1" implies the query should be interpreted verbatim,
|
||||
# which is accomplished by wrapping the query in double quotes
|
||||
if 'li:1' in href:
|
||||
query_link = '"' + query_link + '"'
|
||||
new_search = 'search?q=' + self.encrypt_path(query_link)
|
||||
query = '"' + query + '"'
|
||||
new_search = 'search?q=' + self.encrypt_path(query)
|
||||
|
||||
query_params = parse_qs(urlparse.urlparse(href).query)
|
||||
for param in VALID_PARAMS:
|
||||
|
@ -234,11 +247,15 @@ class Filter:
|
|||
link['href'] = new_search
|
||||
elif 'url?q=' in href:
|
||||
# Strip unneeded arguments
|
||||
link['href'] = filter_link_args(query_link)
|
||||
link['href'] = filter_link_args(query)
|
||||
|
||||
# Add no-js option
|
||||
if self.nojs:
|
||||
append_nojs(link)
|
||||
else:
|
||||
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
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ from stem import Signal, SocketError
|
|||
from stem.control import Controller
|
||||
|
||||
SEARCH_URL = 'https://www.google.com/search?gbv=1&q='
|
||||
MAPS_URL = 'https://maps.google.com/maps'
|
||||
AUTOCOMPLETE_URL = ('https://suggestqueries.google.com/'
|
||||
'complete/search?client=toolbar&')
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ from flask import jsonify, make_response, request, redirect, render_template, \
|
|||
from requests import exceptions
|
||||
|
||||
from app import app
|
||||
from app.filter import strip_blocked_sites
|
||||
from app.models.config import Config
|
||||
from app.request import Request, TorError
|
||||
from app.utils.bangs import resolve_bang
|
||||
|
@ -247,7 +248,7 @@ def search():
|
|||
'header.html',
|
||||
config=g.user_config,
|
||||
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,
|
||||
mobile=g.user_request.mobile)
|
||||
if 'isch' not in search_util.search_type else '')), resp_code
|
||||
|
|
|
@ -54,5 +54,33 @@
|
|||
"apply": "Aplicar",
|
||||
"save-as": "Guardar como...",
|
||||
"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"
|
||||
name="q"
|
||||
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"
|
||||
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 name="tbm" value="{{ search_type }}" style="display: none">
|
||||
<input type="submit" style="display: none;">
|
||||
|
@ -54,7 +54,7 @@
|
|||
name="q"
|
||||
spellcheck="false"
|
||||
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;
|
||||
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' }};">
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
from app.filter import Filter, get_first_link
|
||||
from app.request import gen_query
|
||||
import os
|
||||
from typing import Any
|
||||
|
||||
from bs4 import BeautifulSoup as bsoup
|
||||
from cryptography.fernet import Fernet, InvalidToken
|
||||
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>'
|
||||
CAPTCHA = 'div class="g-recaptcha"'
|
||||
|
|
2
setup.py
2
setup.py
|
@ -8,7 +8,7 @@ setuptools.setup(
|
|||
author='Ben Busby',
|
||||
author_email='benbusby@protonmail.com',
|
||||
name='whoogle-search',
|
||||
version='0.5.0',
|
||||
version='0.5.1',
|
||||
include_package_data=True,
|
||||
install_requires=requirements,
|
||||
description='Self-hosted, ad-free, privacy-respecting metasearch engine',
|
||||
|
|
Loading…
Reference in New Issue
Block a user