my eye

Hide web results from non-owner users

Committed 216b42

--- a/webint_search/__init__.py
+++ b/webint_search/__init__.py

                 pass
             rhymes = pronouncing.rhymes(query)
 
-        web_results = [
-            (
-                webagt.uri(webagt.uri(result.element.attrib["href"])["uddg"][0]),
-                result.element.text if result.element.text is not None else "",
-            )
-            for result in webagt.get(
-                f"https://html.duckduckgo.com/html?q={query}"
-            ).dom.select(".result__a")
-        ]
+        if web.tx.user.is_owner:
+            web_results = [
+                (
+                    webagt.uri(webagt.uri(result.element.attrib["href"])["uddg"][0]),
+                    result.element.text if result.element.text is not None else "",
+                )
+                for result in webagt.get(
+                    f"https://html.duckduckgo.com/html?q={query}"
+                ).dom.select(".result__a")
+            ]
+        else:
+            web_results = None
 
         code_projects = collections.Counter()
         code_files = collections.defaultdict(list)

--- a/webint_search/templates/results.html
+++ b/webint_search/templates/results.html

     <p><strong title="$cmu_pronunciation">$ipa_pronunciation</strong>, $definition<br>
     <small>rhymes: $", ".join(rhymes)</small></p>
 
-<h2>Across the Web</h2>
-$if web_results:
-    <div>
-    $ featured_sites = {
-    $   "$tx.host.name": ("$tx.origin/media/6ysi.png", " — $tx.host.owner['name'][0]"),
-    $   "indieweb.org": ("https://indieweb.org/favicon.ico", " - IndieWeb"),
-    $   "en.wikipedia.org": ("https://www.wikipedia.org/static/favicon/wikipedia.ico", " - Wikipedia"),
-    $   "www.youtube.com": ("https://www.youtube.com/s/desktop/a24ea7cc/img/favicon.ico", " - YouTube"),
-    $   "developer.mozilla.org": ("https://developer.mozilla.org/favicon-48x48.cbbd161b.png", " | MDN - MDN Web Docs"),
-    $   "www.w3.org": ("https://www.w3.org/favicon.ico", " - World Wide Web Consortium (W3C)"),
-    $   "stackoverflow.com": ("https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico?v=ec617d715196", " - Stack Overflow"),
-    $   "www.imdb.com": ("https://m.media-amazon.com/images/G/01/imdb/images-ANDW73HA/favicon_desktop_32x32._CB1582158068_.png", " - IMDb"),
-    $   "docs.python.org": ("https://docs.python.org/3/_static/py.svg", " — Python \d\.\d{,2}\.0.+")
-    $ }
-    $ blocked_sites = (
-    $   "www.$tx.host.name",
-    $   "www.freecodecamp.org",
-    $   "www.tutorialspoint.com",
-    $   "www.w3schools.com",
-    $ )
-    <div>
-    $for result_url, result_text in web_results:
-        $ opacity = .75
-        $ font_size = "1em"
-        $ icon = None
-        $ suffix = ""
-        $if result_url.host in featured_sites:
-            $ font_size = "1.25em"
-            $ icon, suffix = featured_sites[result_url.host]
-            $ opacity = 1
-            $if result_url.host == "developer.mozilla.org" and not result_url.path.startswith("en-US"):
+$if tx.user.is_owner:
+    <h2>Across the Web</h2>
+    $if web_results:
+        <div>
+        $ featured_sites = {
+        $   "$tx.host.name": ("$tx.origin/media/6ysi.png", " — $tx.host.owner['name'][0]"),
+        $   "indieweb.org": ("https://indieweb.org/favicon.ico", " - IndieWeb"),
+        $   "en.wikipedia.org": ("https://www.wikipedia.org/static/favicon/wikipedia.ico", " - Wikipedia"),
+        $   "www.youtube.com": ("https://www.youtube.com/s/desktop/a24ea7cc/img/favicon.ico", " - YouTube"),
+        $   "developer.mozilla.org": ("https://developer.mozilla.org/favicon-48x48.cbbd161b.png", " | MDN - MDN Web Docs"),
+        $   "www.w3.org": ("https://www.w3.org/favicon.ico", " - World Wide Web Consortium (W3C)"),
+        $   "stackoverflow.com": ("https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico?v=ec617d715196", " - Stack Overflow"),
+        $   "www.imdb.com": ("https://m.media-amazon.com/images/G/01/imdb/images-ANDW73HA/favicon_desktop_32x32._CB1582158068_.png", " - IMDb"),
+        $   "docs.python.org": ("https://docs.python.org/3/_static/py.svg", " — Python \d\.\d{,2}\.0.+")
+        $ }
+        $ blocked_sites = (
+        $   "www.$tx.host.name",
+        $   "www.freecodecamp.org",
+        $   "www.tutorialspoint.com",
+        $   "www.w3schools.com",
+        $ )
+        <div>
+        $for result_url, result_text in web_results:
+            $ opacity = .75
+            $ font_size = "1em"
+            $ icon = None
+            $ suffix = ""
+            $if result_url.host in featured_sites:
+                $ font_size = "1.25em"
+                $ icon, suffix = featured_sites[result_url.host]
+                $ opacity = 1
+                $if result_url.host == "developer.mozilla.org" and not result_url.path.startswith("en-US"):
+                    $continue
+            $elif result_url.host in blocked_sites:
                 $continue
-        $elif result_url.host in blocked_sites:
-            $continue
-        <div style="opacity:$opacity;line-height:1;margin:.25em 0">
-        <a href=$result_url>$re.sub(f"{suffix}$", "", result_text)</a><br>
-        <small><small>
-        $if icon:
-            <img style=height:1.25em;position:relative;top:.225em src=$icon>&ensp;\
-            $str(result_url).removeprefix(f"{result_url.origin}/")
-        $else:
-            $result_url
-        </small></small>
+            <div style="opacity:$opacity;line-height:1;margin:.25em 0">
+            <a href=$result_url>$re.sub(f"{suffix}$", "", result_text)</a><br>
+            <small><small>
+            $if icon:
+                <img style=height:1.25em;position:relative;top:.225em src=$icon>&ensp;\
+                $str(result_url).removeprefix(f"{result_url.origin}/")
+            $else:
+                $result_url
+            </small></small>
+            </div>
         </div>
-    </div>
-    </div>
-$else:
-    <p>0 results</p>
+        </div>
+    $else:
+        <p>0 results</p>
 
 <h2>Code</h2>
 $if code_projects.most_common()[0][0]: