User:GreenC bot/Job 9/source

::

  1. !/usr/bin/gawk -bE
  1. shorty - convert magic keyword {{SHORTDESC:}} to {{Short description:<title>}}</li> <li>and move to top of page.</li> <li>https://en.wikipedia.org/wiki/User:GreenC_bot/Job_9</li> <li></li> <li>The MIT License (MIT)</li> <li></li> <li>Copyright (c) January 2019</li> <li></li> <li>Permission is hereby granted, free of charge, to any person obtaining a copy</li> <li>of this software and associated documentation files (the "Software"), to deal</li> <li>in the Software without restriction, including without limitation the rights</li> <li>to use, copy, modify, merge, publish, distribute, sublicense, and/or sell</li> <li>copies of the Software, and to permit persons to whom the Software is</li> <li>furnished to do so, subject to the following conditions:</li> <li></li> <li>The above copyright notice and this permission notice shall be included in</li> <li>all copies or substantial portions of the Software.</li> <li></li> <li>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR</li> <li>IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</li> <li>FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</li> <li>AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</li> <li>LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,</li> <li>OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN</li> <li>THE SOFTWARE.</li> </ol> <ol> <li>Dependency:</li> <li>https://github.com/greencardamom/BotWikiAwk</li> </ol> <p>BEGIN {</p> <p>BotName = "shorty"</p> <p>}</p> <p>@include "botwiki.awk"</p> <p>@include "library.awk"</p> <p>BEGIN {</p> <p>Email = "<email addr>"</p> <p>Exe["mailx"] = "/usr/bin/mailx"</p> <p>Log = Home "log/"</p> <p>Re1 = "[{][ ]*[{][ ]*SHORTDESC[ ]*[:][ ]*[^}]*[}][ ]*[}][ ]*[\n]?"</p> <p>Re2 = "^([{][ ]*[{][ ]*SHORTDESC[ ]*[:][ ]*)|([ ]*[}][ ]*[}][ ]*[\n]?)$"</p> <p>Sum = "Convert SHORTDESC magic keyword to template (via <a href='?title=User%3AGreenC_bot%2FJob_9'>shorty</a> bot)"</p> <p>main()</p> <p>}</p> <p>function main( list,i,name,fp,c,field,seps,sdt,done,k,a) {</p> <p>list = sys2var(Exe["wikiget"] " -a insource:SHORTDESC") # download list of articles from an insource: search</p> <p>if ( list) {</p> <p>for(i = 1; i <= splitn(list "\n", name, i); i++) { # split list and iterate</p> <p>fp = sys2var(Exe["wikiget"] " -w " shquote(name[i])) # download article wikisource</p> <p>if ( match(stripnowikicom(fp), Re1) ) { # skip any in nowiki and wikicomment</p> <p>c = patsplit(fp, field, Re1, seps) # extract the magic word into field[1]</p> <p>if ( c == 1 ) { # if more than 1 throw error and skip</p> <p># stdErr("Processing " name[i]) # debugging</p> <p>sdt = gsubi(Re2, "", field[1]) # save magic word description</p> <p>field[1] = "" # delete magic word</p> <p>fp = unpatsplit(field, seps) # rebuild article without it</p> <p>fp = "{{Short description|" sdt "}}\n" fp # rebuild article with new template prepended at top</p> <p>IGNORECASE=1 # case insensitive</p> <p>upload(fp, name[i], Sum, Log, BotName, "en") # upload new article</p> <p>done[name[i]] = 1 # log done</p> <p># if(i==4) break # debugging</p> <p>}</p> <p>else {</p> <p>print name[i] " --- Error: too many or too few SHORTDESC" >> Log "error"</p> <p>}</p> <p>}</p> <p>}</p> <p>}</p> <p># Email result</p> <p>if(length(done) > 0) {</p> <p>print "\nPages processed: " length(name) > Log "email"</p> <p>print "\nPages fixed: \n" >> Log "email"</p> <p>for(k in done)</p> <p>print "\t" k >> Log "email"</p> <p>sleep(60) # Give wiki servers time to catch up</p> <p>print "\nPages not fixed: " splitn(sys2var(Exe["wikiget"] " -a insource:SHORTDESC") "\n", a) >> Log "email"</p> <p>print "\nSearch for not fixed: insource:SHORTDESC\n" >> Log "email"</p> <p>close(Log "email")</p> <p>sys2var(Exe["mailx"] " -s \"NOTICE: Shorty bot fixed " length(done) " pages.\" " Email " < " Log "email")</p> <p>}</p> <p>}</p> <p></syntaxhighlight></p></div></section></div></main> <footer class="site-footer"> <div class="footer-container"> <div class="footer-links"> <a href="/about.php">About</a> <a href="/help.php">Help</a> <a href="/updates.php">Updates</a> <a href="/contact.php">Contact</a> <a href="/privacy.php">Privacy</a> <a href="/terms.php">Terms</a> <a href="https://github.com/yourusername/friendly-wiki" target="_blank" rel="noopener">GitHub</a> </div> <div class="footer-copy"> © 2025 Friendly Wiki. All rights reserved. </div> </div> </footer> <script> const toggle = document.getElementById('mobileMenuToggle'); const menu = document.getElementById('mobileMenu'); toggle.addEventListener('click', () => { menu.classList.toggle('active'); }); </script> <!-- Collapsible toggle --> <script> document.addEventListener("DOMContentLoaded", function () { const toggles = document.querySelectorAll('.section-toggle'); toggles.forEach(toggle => { toggle.addEventListener('click', function () { const section = toggle.closest('.collapsible'); const body = section.querySelector('.wiki-body'); body.classList.toggle('collapsed'); }); }); }); </script>