Manual:Pywikibot/PAWS/ko


 * 더 자세한 사항은 PAWS에서 확인하세요.

이 문서는 PAWS(Pywikibot: A Web Shell)를 이용하여 위키미디어 실험실 환경의 노트북을 이용한 Pywikibot의 빠른 대화형 개요를 제공합니다.

위키미디어 계정 만들기
To follow this walk-through, you only need a Wikipedia/Wikimedia account. Use Special:CreateAccount to create one.

Once you have created an account, please visit https://test.wikipedia.org/ and check that your username appears in the top right corner (this works around T120327).

노트북으로 접속하기
노트북에서 진행을 시작하려면, 여기로 가세요.

‘Sign in with MediaWiki’를 클릭하고 나서 ‘OAuth 이용 인증’에 동의하는지 물어볼 때 ‘허용합니다’를 클릭합니다. PAWS에 처음 접속하려면, 서버 생성이 필요합니다. 초록색 ‘Start my Server’ 버튼을 클릭합니다. It's normal to wait a few minutes for the new server to start up.

Once that is completed, you will be redirected to a URL like https://paws.wmflabs.org/paws/user/ /tree

장치 시작하기
새로운 대화형 장치를 시작하기 위해,
 * 1) PAWS 대문에 가서
 * 2) ‘New’를 오른쪽 버튼으로 클릭하고
 * 3) ‘Terminal’을 선택합니다.

이러면 리눅스‘$’프롬프트와 함께 https://paws.wmflabs.org/paws/user/ /terminals/1 URL의 새로운 창이 열립니다.

You can bookmark this URL, and return to the terminal at any time, even after you have closed your browser or shutdown your own computer.

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.

위키에 로그인하기
이는 서버 내에 계정이 만들어질 것이고 명령어 줄에서 로그인이 허가됩니다. The following command should confirm that you can log into the testwiki. It uses OAuth, so there is no need to enter a password.

You can connect pywikibot to a different wiki by creating a file named user-config.py in your  directory  and adding mylang and family variables:

문서 만들기
To create a page, enter the following command in the terminal, replacing ' ' with your username, and pressing 'Y' when prompted to accept your changes:

You have edited the wiki. View your changes by opening https://test.wikipedia.org/wiki/User_talk: in your web browser.

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

문서 꺼내오기
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.

실제 스크립트 예시
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.

이제 빠진 ‘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.

Pywikibot 내부
다음은 PAWS 파이썬 섹션을 사용합니다.


 * 1) PAWS 대문에 가서
 * 2) ‘New’를 오른쪽 버튼으로 클릭하고
 * 3) ‘Python 3’을 선택합니다.

이러면 새로운 창이 열립니다.

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.

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:

또는

Pywikibot 스크립트 편집하기
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

같이 보기

 * 한 사용자의 PAWS 요약(예: API 및 데이터베이스 접근)