diff options
Diffstat (limited to 'src/searx.plugins.unit_converter.html')
-rw-r--r-- | src/searx.plugins.unit_converter.html | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/src/searx.plugins.unit_converter.html b/src/searx.plugins.unit_converter.html new file mode 100644 index 000000000..28c2c8d42 --- /dev/null +++ b/src/searx.plugins.unit_converter.html @@ -0,0 +1,212 @@ +<!DOCTYPE html> + +<html lang="en" data-content_root="../"> + <head> + <meta charset="utf-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>Unit converter plugin — SearXNG Documentation (2025.1.6+6dab7fe78)</title> + <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=4f649999" /> + <link rel="stylesheet" type="text/css" href="../_static/searxng.css?v=52e4ff28" /> + <script src="../_static/documentation_options.js?v=ef740023"></script> + <script src="../_static/doctools.js?v=9a2dae69"></script> + <script src="../_static/sphinx_highlight.js?v=dc90522c"></script> + <script data-project="searxng" data-version="2025.1.6+6dab7fe78" src="../_static/describe_version.js?v=fa7f30d0"></script> + <link rel="index" title="Index" href="../genindex.html" /> + <link rel="search" title="Search" href="../search.html" /> + <link rel="next" title="Redis DB" href="searx.redisdb.html" /> + <link rel="prev" title="Tor check plugin" href="searx.plugins.tor_check.html" /> + </head><body> + <div class="related" role="navigation" aria-label="Related"> + <h3>Navigation</h3> + <ul> + <li class="right" style="margin-right: 10px"> + <a href="../genindex.html" title="General Index" + accesskey="I">index</a></li> + <li class="right" > + <a href="../py-modindex.html" title="Python Module Index" + >modules</a> |</li> + <li class="right" > + <a href="searx.redisdb.html" title="Redis DB" + accesskey="N">next</a> |</li> + <li class="right" > + <a href="searx.plugins.tor_check.html" title="Tor check plugin" + accesskey="P">previous</a> |</li> + <li class="nav-item nav-item-0"><a href="../index.html">SearXNG Documentation (2025.1.6+6dab7fe78)</a> »</li> + <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Source-Code</a> »</li> + <li class="nav-item nav-item-this"><a href="">Unit converter plugin</a></li> + </ul> + </div> + + <div class="document"> + <div class="documentwrapper"> + <div class="bodywrapper"> + <div class="body" role="main"> + + <section id="unit-converter-plugin"> +<span id="id1"></span><h1>Unit converter plugin<a class="headerlink" href="#unit-converter-plugin" title="Link to this heading">¶</a></h1> +<p id="module-searx.plugins.unit_converter">A plugin for converting measured values from one unit to another unit (a +unit converter).</p> +<p>The plugin looks up the symbols (given in the query term) in a list of +converters, each converter is one item in the list (compare +<a class="reference internal" href="#searx.plugins.unit_converter.ADDITIONAL_UNITS" title="searx.plugins.unit_converter.ADDITIONAL_UNITS"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ADDITIONAL_UNITS</span></code></a>). If the symbols are ambiguous, the matching units +of measurement are evaluated. The weighting in the evaluation results from the +sorting of the <a class="reference internal" href="#searx.plugins.unit_converter.symbol_to_si" title="searx.plugins.unit_converter.symbol_to_si"><code class="xref py py-obj docutils literal notranslate"><span class="pre">list</span> <span class="pre">of</span> <span class="pre">unit</span> <span class="pre">converters</span></code></a>.</p> +<p>Enable in <code class="docutils literal notranslate"><span class="pre">settings.yml</span></code>:</p> +<div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="nt">enabled_plugins</span><span class="p">:</span> +<span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">..</span> +<span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">- 'Unit converter plugin'</span> +</pre></div> +</div> +<dl class="py function"> +<dt class="sig sig-object py" id="searx.plugins.unit_converter.symbol_to_si"> +<span class="sig-prename descclassname"><span class="pre">searx.plugins.unit_converter.</span></span><span class="sig-name descname"><span class="pre">symbol_to_si</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/searx/plugins/unit_converter.html#symbol_to_si"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#searx.plugins.unit_converter.symbol_to_si" title="Link to this definition">¶</a></dt> +<dd><p>Generates a list of tuples, each tuple is a measure unit and the fields +in the tuple are:</p> +<ol class="arabic simple" start="0"> +<li><p>Symbol of the measure unit (e.g. ‘mi’ for measure unit ‘miles’ Q253276)</p></li> +<li><p>SI name of the measure unit (e.g. Q11573 for SI unit ‘metre’)</p></li> +<li><p>Factor to get SI value from measure unit (e.g. 1mi is equal to SI 1m +multiplied by 1609.344)</p></li> +<li><p>Factor to get measure value from from SI value (e.g. SI 100m is equal to +100mi divided by 1609.344)</p></li> +</ol> +<p>The returned list is sorted, the first items are created from +<code class="docutils literal notranslate"><span class="pre">WIKIDATA_UNITS</span></code>, the second group of items is build from +<a class="reference internal" href="#searx.plugins.unit_converter.ADDITIONAL_UNITS" title="searx.plugins.unit_converter.ADDITIONAL_UNITS"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ADDITIONAL_UNITS</span></code></a> and items created from <a class="reference internal" href="#searx.plugins.unit_converter.ALIAS_SYMBOLS" title="searx.plugins.unit_converter.ALIAS_SYMBOLS"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ALIAS_SYMBOLS</span></code></a>.</p> +<p>If you search this list for a symbol, then a match with a symbol from +Wikidata has the highest weighting (first hit in the list), followed by the +symbols from the <a class="reference internal" href="#searx.plugins.unit_converter.ADDITIONAL_UNITS" title="searx.plugins.unit_converter.ADDITIONAL_UNITS"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ADDITIONAL_UNITS</span></code></a> and the lowest weighting is +given to the symbols resulting from the aliases <a class="reference internal" href="#searx.plugins.unit_converter.ALIAS_SYMBOLS" title="searx.plugins.unit_converter.ALIAS_SYMBOLS"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ALIAS_SYMBOLS</span></code></a>.</p> +</dd></dl> + +<dl class="py data"> +<dt class="sig sig-object py" id="searx.plugins.unit_converter.ADDITIONAL_UNITS"> +<span class="sig-prename descclassname"><span class="pre">searx.plugins.unit_converter.</span></span><span class="sig-name descname"><span class="pre">ADDITIONAL_UNITS</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">[{'from_si':</span> <span class="pre"><function</span> <span class="pre"><lambda>>,</span> <span class="pre">'si_name':</span> <span class="pre">'Q11579',</span> <span class="pre">'symbol':</span> <span class="pre">'°C',</span> <span class="pre">'to_si':</span> <span class="pre"><function</span> <span class="pre"><lambda>>},</span> <span class="pre">{'from_si':</span> <span class="pre"><function</span> <span class="pre"><lambda>>,</span> <span class="pre">'si_name':</span> <span class="pre">'Q11579',</span> <span class="pre">'symbol':</span> <span class="pre">'°F',</span> <span class="pre">'to_si':</span> <span class="pre"><function</span> <span class="pre"><lambda>>}]</span></em><a class="headerlink" href="#searx.plugins.unit_converter.ADDITIONAL_UNITS" title="Link to this definition">¶</a></dt> +<dd><p>Additional items to convert from a measure unit to a SI unit (vice versa).</p> +<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="p">{</span> + <span class="s2">"si_name"</span><span class="p">:</span> <span class="s2">"Q11579"</span><span class="p">,</span> <span class="c1"># Wikidata item ID of the SI unit (Kelvin)</span> + <span class="s2">"symbol"</span><span class="p">:</span> <span class="s2">"°C"</span><span class="p">,</span> <span class="c1"># symbol of the measure unit</span> + <span class="s2">"to_si"</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">val</span><span class="p">:</span> <span class="n">val</span> <span class="o">+</span> <span class="mf">273.15</span><span class="p">,</span> <span class="c1"># convert measure value (val) to SI unit</span> + <span class="s2">"from_si"</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">val</span><span class="p">:</span> <span class="n">val</span> <span class="o">-</span> <span class="mf">273.15</span><span class="p">,</span> <span class="c1"># convert SI value (val) measure unit</span> +<span class="p">},</span> +<span class="p">{</span> + <span class="s2">"si_name"</span><span class="p">:</span> <span class="s2">"Q11573"</span><span class="p">,</span> + <span class="s2">"symbol"</span><span class="p">:</span> <span class="s2">"mi"</span><span class="p">,</span> + <span class="s2">"to_si"</span><span class="p">:</span> <span class="mf">1609.344</span><span class="p">,</span> <span class="c1"># convert measure value (val) to SI unit</span> + <span class="s2">"from_si"</span><span class="p">:</span> <span class="mi">1</span> <span class="o">/</span> <span class="mf">1609.344</span> <span class="c1"># convert SI value (val) measure unit</span> +<span class="p">},</span> +</pre></div> +</div> +<p>The values of <code class="docutils literal notranslate"><span class="pre">to_si</span></code> and <code class="docutils literal notranslate"><span class="pre">from_si</span></code> can be of <a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.13)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">float</span></code></a> (a multiplier) +or a <a class="reference external" href="https://docs.python.org/3/glossary.html#term-callable">callable</a> (val in / converted value returned).</p> +</dd></dl> + +<dl class="py data"> +<dt class="sig sig-object py" id="searx.plugins.unit_converter.ALIAS_SYMBOLS"> +<span class="sig-prename descclassname"><span class="pre">searx.plugins.unit_converter.</span></span><span class="sig-name descname"><span class="pre">ALIAS_SYMBOLS</span></span><em class="property"><span class="w"> </span><span class="p"><span class="pre">=</span></span><span class="w"> </span><span class="pre">{'mi':</span> <span class="pre">('L',),</span> <span class="pre">'°C':</span> <span class="pre">('C',),</span> <span class="pre">'°F':</span> <span class="pre">('F',)}</span></em><a class="headerlink" href="#searx.plugins.unit_converter.ALIAS_SYMBOLS" title="Link to this definition">¶</a></dt> +<dd><p>Alias symbols for known unit of measure symbols / by example:</p> +<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="s1">'°C'</span><span class="p">:</span> <span class="p">(</span><span class="s1">'C'</span><span class="p">,</span> <span class="o">...</span><span class="p">),</span> <span class="c1"># list of alias symbols for °C (Q69362731)</span> +<span class="s1">'°F'</span><span class="p">:</span> <span class="p">(</span><span class="s1">'F'</span><span class="p">,</span> <span class="o">...</span><span class="p">),</span> <span class="c1"># list of alias symbols for °F (Q99490479)</span> +<span class="s1">'mi'</span><span class="p">:</span> <span class="p">(</span><span class="s1">'L'</span><span class="p">,),</span> <span class="c1"># list of alias symbols for mi (Q253276)</span> +</pre></div> +</div> +</dd></dl> + +</section> + + + <div class="clearer"></div> + </div> + </div> + </div> + <span id="sidebar-top"></span> + <div class="sphinxsidebar" role="navigation" aria-label="Main"> + <div class="sphinxsidebarwrapper"> + + + <p class="logo"><a href="../index.html"> + <img class="logo" src="../_static/searxng-wordmark.svg" alt="Logo of SearXNG"/> + </a></p> + + +<h3><a href="../index.html">Table of Contents</a></h3> +<ul class="current"> +<li class="toctree-l1"><a class="reference internal" href="../user/index.html">User information</a></li> +<li class="toctree-l1"><a class="reference internal" href="../own-instance.html">Why use a private instance?</a></li> +<li class="toctree-l1"><a class="reference internal" href="../admin/index.html">Administrator documentation</a></li> +<li class="toctree-l1"><a class="reference internal" href="../dev/index.html">Developer documentation</a></li> +<li class="toctree-l1"><a class="reference internal" href="../utils/index.html">DevOps tooling box</a></li> +<li class="toctree-l1 current"><a class="reference internal" href="index.html">Source-Code</a><ul class="current"> +<li class="toctree-l2"><a class="reference internal" href="searx.babel_extract.html">Custom message extractor (i18n)</a></li> +<li class="toctree-l2"><a class="reference internal" href="searx.botdetection.html">Bot Detection</a></li> +<li class="toctree-l2"><a class="reference internal" href="searx.exceptions.html">SearXNG Exceptions</a></li> +<li class="toctree-l2"><a class="reference internal" href="searx.favicons.html">Favicons (source)</a></li> +<li class="toctree-l2"><a class="reference internal" href="searx.infopage.html">Online <code class="docutils literal notranslate"><span class="pre">/info</span></code></a></li> +<li class="toctree-l2"><a class="reference internal" href="searx.locales.html">Locales</a></li> +<li class="toctree-l2"><a class="reference internal" href="searx.plugins.hostnames.html">Hostnames plugin</a></li> +<li class="toctree-l2"><a class="reference internal" href="searx.plugins.tor_check.html">Tor check plugin</a></li> +<li class="toctree-l2 current"><a class="current reference internal" href="#">Unit converter plugin</a><ul> +<li class="toctree-l3"><a class="reference internal" href="#searx.plugins.unit_converter.symbol_to_si"><code class="docutils literal notranslate"><span class="pre">symbol_to_si()</span></code></a></li> +<li class="toctree-l3"><a class="reference internal" href="#searx.plugins.unit_converter.ADDITIONAL_UNITS"><code class="docutils literal notranslate"><span class="pre">ADDITIONAL_UNITS</span></code></a></li> +<li class="toctree-l3"><a class="reference internal" href="#searx.plugins.unit_converter.ALIAS_SYMBOLS"><code class="docutils literal notranslate"><span class="pre">ALIAS_SYMBOLS</span></code></a></li> +</ul> +</li> +<li class="toctree-l2"><a class="reference internal" href="searx.redisdb.html">Redis DB</a></li> +<li class="toctree-l2"><a class="reference internal" href="searx.redislib.html">Redis Library</a></li> +<li class="toctree-l2"><a class="reference internal" href="searx.search.html">Search</a></li> +<li class="toctree-l2"><a class="reference internal" href="searx.search.processors.html">Search processors</a></li> +<li class="toctree-l2"><a class="reference internal" href="searx.settings.html">Settings Loader</a></li> +<li class="toctree-l2"><a class="reference internal" href="searx.sqlitedb.html">SQLite DB</a></li> +<li class="toctree-l2"><a class="reference internal" href="searx.utils.html">Utility functions for the engines</a></li> +</ul> +</li> +</ul> + + <h3>Project Links</h3> + <ul> + <li><a href="https://github.com/searxng/searxng/tree/master">Source</a> + + <li><a href="https://github.com/searxng/searxng/wiki">Wiki</a> + + <li><a href="https://searx.space">Public instances</a> + + <li><a href="https://github.com/searxng/searxng/issues">Issue Tracker</a> + </ul><h3>Navigation</h3> +<ul> + <li><a href="../index.html">Overview</a> + <ul> + <li><a href="index.html">Source-Code</a> + <ul> + <li>Previous: <a href="searx.plugins.tor_check.html" title="previous chapter">Tor check plugin</a> + <li>Next: <a href="searx.redisdb.html" title="next chapter">Redis DB</a></ul> + </li> + </ul> + </li> +</ul> +<search id="searchbox" style="display: none" role="search"> + <h3 id="searchlabel">Quick search</h3> + <div class="searchformwrapper"> + <form class="search" action="../search.html" method="get"> + <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/> + <input type="submit" value="Go" /> + </form> + </div> +</search> +<script>document.getElementById('searchbox').style.display = "block"</script> + <div role="note" aria-label="source link"> + <h3>This Page</h3> + <ul class="this-page-menu"> + <li><a href="../_sources/src/searx.plugins.unit_converter.rst.txt" + rel="nofollow">Show Source</a></li> + </ul> + </div> + </div> + </div> + <div class="clearer"></div> + </div> + <div class="footer" role="contentinfo"> + © Copyright SearXNG team. + </div> + </body> +</html>
\ No newline at end of file |