Skip to content

Commit

Permalink
Update several functions and docs pages
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasdabbas committed Apr 1, 2024
1 parent 86a3d32 commit ed44c2d
Show file tree
Hide file tree
Showing 28 changed files with 1,524 additions and 1,179 deletions.
Binary file modified docs/_build/doctrees/advertools.ad_from_string.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/advertools.header_spider.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/advertools.image_spider.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/advertools.kw_generate.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/advertools.reverse_dns_lookup.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/advertools.serp.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/advertools.word_frequency.doctree
Binary file not shown.
Binary file modified docs/_build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/_build/doctrees/include_changelog.doctree
Binary file not shown.
50 changes: 32 additions & 18 deletions docs/_build/html/_modules/advertools/ad_from_string.html
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ <h1>Source code for advertools.ad_from_string</h1><div class="highlight"><pre>

<span class="sd">.. code-block:</span>

<span class="sd"> [&#39;Get the latest gadget online. The GX12 model comes with 13 things that do a lot of good stuff for your health. Start shopping&#39;,</span>
<span class="sd"> [&#39;Get the latest gadget online. The GX12 model comes with 13 things that do a lot\</span>
<span class="sd"> of good stuff for your health. Start shopping&#39;,</span>
<span class="sd"> &#39;now.&#39;,</span>
<span class="sd"> &#39;&#39;,</span>
<span class="sd"> &#39;&#39;]</span>
Expand Down Expand Up @@ -279,30 +280,41 @@ <h1>Source code for advertools.ad_from_string</h1><div class="highlight"><pre>
<span class="sd"> [&#39;Get the latest gadget&#39;,</span>
<span class="sd"> &#39;online. The GX12 model comes&#39;,</span>
<span class="sd"> &#39;with 13 things that do a lot of good stuff for your health. Start shopping now.&#39;]</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">&quot;&quot;&quot;</span> <span class="c1"># noqa: E501</span>

<span class="kn">import</span> <span class="nn">string</span>


<div class="viewcode-block" id="ad_from_string">
<a class="viewcode-back" href="../../advertools.ad_from_string.html#advertools.ad_from_string.ad_from_string">[docs]</a>
<span class="k">def</span> <span class="nf">ad_from_string</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">slots</span><span class="o">=</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">90</span><span class="p">,</span> <span class="mi">90</span><span class="p">,</span> <span class="mi">15</span><span class="p">,</span> <span class="mi">15</span><span class="p">),</span> <span class="n">sep</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">capitalize</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">ad_from_string</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">slots</span><span class="o">=</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">30</span><span class="p">,</span> <span class="mi">90</span><span class="p">,</span> <span class="mi">90</span><span class="p">,</span> <span class="mi">15</span><span class="p">,</span> <span class="mi">15</span><span class="p">),</span> <span class="n">sep</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">capitalize</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Convert string :attr:`s` to an ad by splitting it into groups of words.</span>

<span class="sd"> Each group would have a length of at most the allowed length for that slot.</span>

<span class="sd"> If the total length of :attr:`s` exceeds the total allowed length, all</span>
<span class="sd"> remaining characters would be grouped in the last element of the</span>
<span class="sd"> returned list.</span>

<span class="sd"> :param str s: a string of characters, with no restrictions on length</span>
<span class="sd"> :param list slots: an iterable of integers for the maximum lengths for</span>
<span class="sd"> each slot</span>
<span class="sd"> :param str sep: character(s) by which to split :attr:`s`</span>
<span class="sd"> :param bool capitalize: whether or not to capitalize each word after</span>
<span class="sd"> grouping. Setting it as False would not change the</span>
<span class="sd"> capitalization of the input string</span>
<span class="sd"> :returns text_ad: a list of strings</span>

<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> s : str</span>
<span class="sd"> A string of characters, with no restrictions on length.</span>
<span class="sd"> slots : list</span>
<span class="sd"> An iterable of integers for the maximum lengths for each slot</span>
<span class="sd"> sep : str</span>
<span class="sd"> Character(s) by which to split :attr:`s`.</span>
<span class="sd"> capitalize : bool</span>
<span class="sd"> Whether or not to capitalize each word after grouping. Setting it as False would</span>
<span class="sd"> not change the capitalization of the input string</span>

<span class="sd"> Returns</span>
<span class="sd"> -------</span>
<span class="sd"> text_ad : list</span>
<span class="sd"> A list of strings according to split spec.</span>

<span class="sd"> Examples</span>
<span class="sd"> --------</span>
<span class="sd"> &gt;&gt;&gt; ad_from_string(&#39;this is a short ad&#39;)</span>
<span class="sd"> [&#39;this is a short ad&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;]</span>

Expand All @@ -323,19 +335,21 @@ <h1>Source code for advertools.ad_from_string</h1><div class="highlight"><pre>
<span class="sd"> &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;, &#39;&#39;]</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">str_words</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">sep</span><span class="o">=</span><span class="n">sep</span><span class="p">)</span>
<span class="n">text_ad</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;&#39;</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">slots</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">)]</span>
<span class="n">text_ad</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;&quot;</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">slots</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)]</span>
<span class="n">counter</span> <span class="o">=</span> <span class="mi">0</span>

<span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">slot</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">slots</span><span class="p">):</span>
<span class="k">while</span> <span class="n">counter</span> <span class="o">&lt;=</span> <span class="nb">len</span><span class="p">(</span><span class="n">str_words</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">text_ad</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+</span> <span class="n">str_words</span><span class="p">[</span><span class="n">counter</span><span class="p">])</span> <span class="o">+</span> <span class="mi">1</span> <span class="o">&gt;</span> <span class="n">slot</span><span class="p">:</span>
<span class="k">break</span>
<span class="n">text_ad</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+=</span> <span class="p">(</span><span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="n">str_words</span><span class="p">[</span><span class="n">counter</span><span class="p">]</span> <span class="k">if</span> <span class="n">text_ad</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
<span class="k">else</span> <span class="n">str_words</span><span class="p">[</span><span class="n">counter</span><span class="p">])</span>
<span class="n">text_ad</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+=</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">str_words</span><span class="p">[</span><span class="n">counter</span><span class="p">]</span> <span class="k">if</span> <span class="n">text_ad</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="k">else</span> <span class="n">str_words</span><span class="p">[</span><span class="n">counter</span><span class="p">]</span>
<span class="n">counter</span> <span class="o">+=</span> <span class="mi">1</span>

<span class="n">text_ad</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="n">sep</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">str_words</span><span class="p">[</span><span class="n">counter</span><span class="p">:])</span>
<span class="k">if</span> <span class="n">sep</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="s1">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">str_words</span><span class="p">[</span><span class="n">counter</span><span class="p">:]))</span>
<span class="n">text_ad</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">sep</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">str_words</span><span class="p">[</span><span class="n">counter</span><span class="p">:])</span>
<span class="k">if</span> <span class="n">sep</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>
<span class="k">else</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">str_words</span><span class="p">[</span><span class="n">counter</span><span class="p">:])</span>
<span class="p">)</span>

<span class="k">return</span> <span class="p">[</span><span class="n">string</span><span class="o">.</span><span class="n">capwords</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">if</span> <span class="n">capitalize</span> <span class="k">else</span> <span class="n">x</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">text_ad</span><span class="p">]</span></div>

Expand Down
Loading

0 comments on commit ed44c2d

Please sign in to comment.