Szerkesztő:BinBot/anniversary.py/doc

A Wikipédiából, a szabad enciklopédiából
Felhasználói információ / User documentation (for developer doc page down)
Évfordulóbot Anniversarybot
A bot célja Purpose
Ez a bot kigyűjti a lehetséges évfordulókat a kezdőlapi sablon elkészítéséhez. A bot adatokat másol a szócikkekből, azok helyességét, forrásait a felhasználó felelőssége ellenőrizni. Lehetséges, hogy valamelyik adat többször is bekerül a listába, ezt sokkal több munka volna programozási eszközökkel kiszűrni, mint figyelmen kívül hagyni. This bot goes through articles and searches for possible anniversaries to help users editing the anniversaries section of the main page. It copies data from articles. Checking the reliability and sources of these is the user's responsibility. Some data may occur repeatedly, as it is much easier to skip them on reading than to prevent duplication by programming.

The code of the bot is published for the wellness of the wider wikicommunity and may be implemented in other Wikipedias by bot owners.

Működése Workflow
A bot a kezdőlapi sablonokhoz igazodva vesz egy dátumot és egy évszámvégződést (pl. /'4, '9/01-13). Először végignézi azokat a cikkeket, amelyek az adott dátum szócikkére linkelnek, majd az összes releváns évszámos szócikket. Amelyik cikkben csak említve van a dátum, de nincs linkelve, az nem fog horogra akadni, mert annyi idő nincs az egész világon. Különben is, ha nincs linkelve, valószínűleg nem is olyan fontos abban a cikkben.

Az általános (nem évszámos) szócikkeket – a refek és a HTML megjegyzések kidobálása után – három részre bontja: fej, tor, potroh

  1. bevezető
  2. az első szakaszcímtől kezdődő tartalmi rész
  3. az első "stopszakaszcímtől" kezdődő cikkvég (==Források==, ==Jegyzetek==, ==Lásd még== stb.)

A végét eldobja, mint a retek ződjét, majd a bevezetőben infoboxokat keres. Infoboxnak nevezzük az olyan sablont, amelynek a nevében szerepel az infobox szó. A többi így járt. Az infoboxokban talált dátumos sorokat paraméter = érték alakban kilistázza. Ezután a bevezetőből eldobja az összes sablont. (A bevezetőben előforduló többi sablon szinte biztosan nem tartalmaz számunkra hasznos dátumot.)

Egy későbbi időpontban a bot talán kikeresi majd a valószínű születési és halálozási dátumokat a bevezetőből, de ez még a jövő zenéje, mert elég bonyolult feladat.

A következő menetben a cikk teljes szövegéből (kivéve az eldobott végét) kigyűjti a dátumot tartalmazó részeket, és +/- 60 karakteres környezetükkel együtt kiírja őket. Technikai okból ezek a részek nowikibe kerülnek. Ez általában elég a találat értékeléséhez.

Végül a megfelelő végződésű évszámos cikkekből kimásol minden olyan sort, ami az adott dátumot tartalmazza. Ez ránézésre általában érthető. Ha csak egy személynév van ott, a mellette levő születési vagy halálozási dátumból következik, hogy ez a találat micsoda; ha pedig nincs mellette semmi, az valószínűleg egy élő ember születési dátuma.

A bot a szövegben és az évszámos cikkek címében is csak az időszámítás szerinti éveket keresi. Az időszámítás előtti évek keresése nagyon lelassítaná (így is 20-30 perc egyetlen oldal elkészítése, vagyis 600-900 óra az összes dátum feldolgozása), másrészt meg a sok naptári változás miatt az ilyen évfordulók megjelenítése amúgy is komolytalan esetleges, és gyakran a megbízhatóságuk is korlátozott.

As Hungarian Wikipedia has the custom to list anniversaries whose elapsed time is divisible by 5, the bot takes a date and a year ending (e.g. /'4, '9/01-13). It reviews the articles linking to the article of the given date and the articles of the years with the given ending. Articles with unlinked mentions of the date will unfortunately be unprocessed as nobody has so much time in the life, and we may assume that important dates are linked. In other Wikipedias the bot owner has the possibility to work with all years, not only those which have the given ending.

From general articles the bot removes text between <ref> tags, HTML comments and the trailing part beginning from the first "stopsection" such as ==Sources==, ==See also== etc. Then it searches the introduction for infoboxes. An infobox is a template the name of which contains a given word (primarily "infobox"). Matches for the desired dates from infoboxes are listed in the format parameter = value. All templates after processing infoboxes are removed from introductory part as the others are usually amboxes, warnings, disambiguation templates and are not likely to contain useful dates.

The bot may search for birth and death dates in introduction at a later time, but this is complicated and is currently not implemented yet.

The remaining text of the article is searched for the occurrences of the date and matches are displayed with their 60 characters long environment before and after. For technical reasons, this text is in nowiki. This lets you overview the matches quite efficiently.

In the next run the bot goes through the articles of years with the given ending and copies all the lines containing the desired date. These may be births, deaths as well as events.

This bot primarily searches dates from AD years. It is rather slow with this setting (20-30 minutes for the medium sized huwiki per date and ending), and searching the BC articles would make it even slower. It is not worth anyhow, due to the several changes in the calendar since that time and the decreased reliability of ancient dates. However, a bot owner may change this behaviour.

Kihagyott lapok Pages that are not processed
A bot nem dolgozza fel a dátumok és hónapok cikkeit, a (keresztnév) kiegészítésű szócikkeket, a kisbolygók listáit (de az egyedi kisbolygós cikkeket igen), az időszámítás előtti éveket és az átirányításokat. Továbbá magának a dátumnak a szócikkét sem, mert az úgy jó, ahogy van, és be van linkelve felül. The bot skips pages determined by the owner. In Hungarian Wikipedia it does not process articles of months, dates, some given names, and skips all the redirects. It will skip the article of the date itself, of course, as it is well written and it is linked from the results.
Bot owners' information
This bot is developed for Hungarian Wikipedia but I think it is easy to port it to another Wikipedia as they usually have similar structures. The source code is at User:BinBot/anniversary.py. The core is class dailybot(). There are two main modes: with yearmodulo5 between 0 and 4 it will search for round anniversaries (having the elapsed time divisible by 5 years to the given ending), while with None it will search for every anniversary, independently from elapsed years. There is also an overwrite parameter which defaults to False; with false bot will skip existing target pages, with True you may force it reprocess such pages.

Currently the bot may work with one given date and year ending wired in main(); or you may use a few predefined sample callers and parameters described in code itself. A caller may process several days in loop. Existing functions allow you to process the next month and show how to create other ones.

Processing a day is not fast (for me it takes 20-30 minutes in huwiki). So a good way to process a whole month may be the repeated use of

anniversary.py nextmonth (or nextmonth5)

and your Ctrl C button when you are fed up. The bot will go through the days of the next month at each run and skip the ready pages quickly, and continue with the first unsaved day.

Structure:

  • dailybot processes one given day with given year endings (round anniversaries or every year).
  • callbot validates the parameters for one day and calls dailybot. Thus dailybot should be called via callbot rather then directly.
  • one_month and nextmonth are sample callers to process a chosen month or the next month.
  • Any further frame may be written to call callbot in loop.

The code is enabled for localization from the first minute. It would bee too complicated to write a general solution but you are welcome to do it. :-) Instead, the script is prepared for modifications. It will require some knowledge of regular expressions. Just follow the instructions in the code, everything is documented. I think it may take 1-2 hours.

First rewrite some global variables at the beginning. These include:

  • stopsections (see the user documentation above)
  • infobox (if infoboxes in your wiki are called "infobox", just leave untouched)
  • basepage – all the results will be subpages of this
  • monthnames – as they appear in article titles
  • exceptions – regexes for titles to skip (months, dates etc. and the bot's own result pages)
  • header – a text that will appear on top of the result pages (if you want to customize it by dates, move it from globals to dailybot)

Then go to dailybot.__init__() and correct regexes there.

You have 3 more methods in dailybot to revise, as described in help.

  • dailybot.datecomposer()
    This is a simple function to produce the date string from month and day. This string should be in the format of your wiki's date articles (e.g. "Január 12." in huwiki).
  • dailybot.categories()
    This is very simple, too. Just put here anything you want to write at the bottom of the pages, primarily categories. The reason it is here and not among globals so that you may customize it with date.
  • dailybot.createpage()
    Outlook of the result page, section titles, a link to the "main article" (the date article itself), a link to the relevant template of anniversaries transcluded to the main page (if your wiki has one), and the edit summary of the bot.

Important information about articles of year numbers: You may see the page generator in dailybot.yearlist(). Site.allpages() generator is filtered with a regex. For that reason after processing the last year (between 995 and 999, alphabetically), you might sit in front of your computer for some days and wait the generator to walk through the alphabet. To prevent the bot wasting your time, a break is applied in dailybot.run(). If you want to enable BC years in your yearregex, you have to modify this limit, too. The new limit varies from language to language. I apologize to my teacher who prefers structured programming.

Finally remove the line "from binbotutils import levelez" from imports and any lines containing "levelez", "hiba" or "fatal" (these serve my own needs, they send me emails with the result of the run and have no control on the script itself).

Please don't forget to link to the original script and this documentation when publishing your modified version. You may wish to display your name under copyright information. :-)

Have fun! Bináris talk