Manual:Pywikibot/PAWS/it


 * Si veda PAWS per i dettagli

Questo documento contiene una veloce panoramica dell'uso di Pywikibot in un quaderno che esegue un'istanza di PAWS (Pywikibot: A Web Shell) presso i Wikimedia labs.

Crea un profilo Wikimedia
Per utilizzare il Terminale PAWS non serve nient'altro che un profilo su un progetto Wikimedia.

Per creare un profilo Wikimedia, si vada alla pagina Accesso del manuale.

Una volta creato il profilo si controlli di aver effettuato l'accesso verificando che il proprio username compaia in alto a destra alla pagina https://test.wikipedia.org

Accedere a un quaderno
Per avviare un quaderno, andare all'indirizzo https://paws.wmflabs.org/paws

Cliccare su accedere con MediaWiki (Sign in with MediaWiki) e permetti (Allow) a Utilizzare OAuth per l'autenticazione ("Use OAuth for Authentication"). La prima volta che accedi a un Terminale PAWS, devi creare un server. Clicca su Avvia il mio server (Start my Server"). Il server potrebbe impiegare qualche minuto ad avviarsi.

Una volta completato, si sarà rediretti all'URL https://paws.wmflabs.org/paws/user/ /tree

Avvia un Terminale
Per avviare un nuovo terminale,
 * 1) vai nella PAWS home di PAWS,
 * 2) clicca Nuovo sul lato destro e
 * 3) seleziona 'Terminale'.

Aprirà una nuova finestra con URL https://paws.wmflabs.org/paws/user/ /terminals/1, contenente un prompt '$' GNU/Linux.

Puoi aggiungere quest'URL ai preferiti e aprire il terminale quando preferisci. Se vuoi interagire con il Terminale come fosse un'applicazione, se usi Chromium puoi cliccare sul pulsante menù in alto a destra, poi su altri strumenti e quindi aggiungi al desktop e barrare la casella (mostra come finestra). A questo punto si potra aprire il Terminale come fosse qualsiasi altro programma installato sul dispositivo.

This terminal is not an emulator. It is a real bash shell, as part of a real Linux installation sitting on a docker container, so you can use any bash command, and use any commands available on Linux that have been installed.

To see some of the commands available, use.

Accedere a una wiki
Pywikibot needs a configuration file 'user-config.py' which PAWS automatically creates for you, with https://test.wikipedia.org/ as the default wiki.

Il seguente comando dovrebbe confermare che la tua utenza è collegata a https://test.wikipedia.org/. Il collegamento utilizza OAuth, quindi non dovrebbe necessario inserire una password.

Creare una pagina
Puoi creare una pagina, inserendo il seguente comando nel Terminale, sostituendo a ' ' il tuo username e premendo 'Y' quando richiesto per confermare le modifiche.

Hai completato la tua prima modifica. Puoi visionare le modifiche apportate alla pagina https://test.wikipedia.org/wiki/User_talk:.

You can read more about each of these command line scripts with the '-help' command line option.

Fetch a page
Fetching many pages is achieved with the "listpages" command.

To get the contents of the page you created in the previous section, enter the following command:

Now if you go to your PAWS files list, the saved page should be present.

A real script example
When a website used on Wikipedia changes its URL, the links on Wikipedia become outdated, and possible also dead links if the website doesn't redirect from the old URLs to the new URLs. e.g. for example, Encyclopedia Britannica (EB) has changed their links, such as moving pages from http://www.britannica.com/EBchecked/media/ to http://www.britannica.com/topic/[topic name]/images-videos/*. You can find the list of usages of the old URL on English Wikipedia at https://en.wikipedia.org/wiki/Special:LinkSearch/http://www.britannica.com/EBchecked/media. Updating all those links manually will be very time consuming. Thankfully EB has maintained redirects from their old URLs to the new URLs, so this does not need to be fixed immediately.

For a simpler example, English Wikipedia currently contains links to http://britannica.com/EBchecked/ instead of http://www.britannica.com/EBchecked/ ; i.e. a 'www.' subdomain is missing in the URL.

There are currently 14 cases on English Wikipedia: https://en.wikipedia.org/wiki/Special:LinkSearch/http://britannica.com/EBchecked/

Wikipedia in other language also have this problem. e.g. there is one case on German Wikipedia: https://de.wikipedia.org/wiki/Spezial:Weblinksuche/http://britannica.com/EBchecked/

In order to fix those links, we can use Pywikibot replace.py script. In this demo we will use the '-simulate' argument to avoid writing to the wiki, as there are strict rules about automated editing of English Wikipedia.

First lets list all of the pages which link to http://britannica.com/EBchecked/.

Now we check those pages actually have the literal URL in the page; i.e. they are not using a template.

Now use replace to add the missing "www."

In PAWS, and any terminal that supports color, the diff of changes will show the added "www." in green text color, making it easier to find the proposed changes.

Inside Pywikibot
Next we will use the PAWS Python session.


 * 1) Go to your PAWS home,
 * 2) click 'New' on the right hand side, and
 * 3) select 'Python 3'.

This will open a new window.

In the text box, enter the following and in the Cell menu select 'Run' (or pressing shift+enter to run).

A new text box will appear below. Run the following to create an APISite object connected to https://test.wikipedia.org/:

Describe "site" by entering it into the new text box and selecting "Run".

It should show

Out[3]: APISite("test", "wikipedia")

Create a page object:

Check it exists by running:

It should output

VERBOSE:pywiki:Found 1 wikipedia:test processes running, including this one. Out[5]: True

Show the text on the page:

Change the page text in the object:

Save the page to the wiki:

The response should be:

The interactive Python 3 notebook allows many lines to be run together. The above could be put into one text box and Run

The log of your interactive Python session can be saved or downloaded for future reference.

Accessing online documentation in PAWS
Pywikibot documentation may be found at https://doc.wikimedia.org/pywikibot/index.html. It is primarily sourced from docstrings, which can be loaded in the interactive Python 3 notebook using the Python built-in function help.

For example, to look at the arguments for the save method above, run either:

or

Editing Pywikibot scripts
The Pywikibot library and scripts are located in /srv/paws, and are read-only. The installed Pywikibot library can not be modified in PAWS.

Scripts may be modified after copying them into your PAWS home.

For example, to run a modified "checkimages.py":
 * 1) In the terminal, enter
 * 2) In a browser, go to your PAWS home and click on the file.
 * 3) In the browser, you can edit the file. Edit the code -- for instance, just after the   code on line 1775, add a new line 1776 that will print out your name:
 * 4) In the editing interface, use the File menu and click Save to save your modifications.
 * 5) In the terminal, enter