Editing DS4UX (Spring 2016)/Wikipedia API
From CommunityData
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
<div style="font-family:Rockwell,'Courier Bold',Courier,Georgia,'Times New Roman',Times,serif; min-width:10em;"> | |||
<div style="float:left; width:100%; margin-right:2%;"> | |||
{{Link/Graphic/Main/2 | |||
|highlight color= 27666b | |||
|color=460c40 | |||
|link= | |||
|image= | |||
|text-align=left | |||
|top font-size= 1.1em | |||
|top color=FFF | |||
|line color=FFF | |||
|top text=This page is a work in progress. | |||
|bottom font-size= 1em | |||
|bottom color= FFF | |||
|bottom text= | |||
|line= none | |||
}}</div></div> | |||
<div style="clear:both;"></div> | |||
[[File:Wikipedia.png|right|250px]] | [[File:Wikipedia.png|right|250px]] | ||
__NOTOC__ | |||
== Getting data from Wikipedia | == Getting data from the Wikipedia API == | ||
In this project, we will explore a few ways to gather data using the Wikipedia API. Once we've done that, we will extend this to code to create our own datasets of Wikipedia edits or other data that we might be able to use to ask and answer questions in future sessions. | In this project, we will explore a few ways to gather data using the Wikipedia API. Once we've done that, we will extend this to code to create our own datasets of Wikipedia edits or other data that we might be able to use to ask and answer questions in future sessions. | ||
Line 13: | Line 32: | ||
* Practice reading and extending other people's code | * Practice reading and extending other people's code | ||
=== Material We Will Cover === | |||
* looking at the images within a page http://en.wikipedia.org/w/api.php?action=query&titles=Seattle&prop=images&imlimit=20&format=jsonfm | |||
:* change the city with a custom URL | |||
* getting individual users' edit counts: http://en.wikipedia.org/w/api.php?action=query&list=users&ususers=Benjamin_Mako_Hill|Jtmorgan|Moonriddengirl|Keilana&usprop=editcount&format=jsonfm | |||
* get the content of the main page http://en.wikipedia.org/w/api.php?format=json&action=query&titles=Main%20Page&prop=revisions&rvprop=content | |||
* example programs: [http://mako.cc/teaching/2014/cdsw-autumn/wikipedia-raw1-unicode-problems-example.py wikipedia-raw1-unicode-problems-example.py] (note: this is an example of Unicode problems when running this on Windows), [http://mako.cc/teaching/2014/cdsw-autumn/wikipedia-raw2-mudslide-edit.py wikipedia-raw2-mudslide-edit.py] | |||
=== Download and test the Wikipedia project === | === Download and test the Wikipedia project === | ||
# Right click the following file, click "Save Target as..." or "Save link as...", and save it to your Desktop directory: FIXME | |||
# The ".zip" extension on the above file indicates that it is a compressed Zip archive. We need to "extract" its contents. | # The ".zip" extension on the above file indicates that it is a compressed Zip archive. We need to "extract" its contents. | ||
Line 23: | Line 49: | ||
python wikipedia1-1.py | python wikipedia1-1.py | ||
== What | == What is Wikipedia? == | ||
* As you probably already know, Wikipedia is a website that anyone can edit. | * As you probably already know, Wikipedia is a website that anyone can edit. | ||
Line 41: | Line 67: | ||
=== Revision metadata === | === Revision metadata === | ||
You can get metadata about a particular revision through the <code>rvprop=</code> parameter. Here are some of the things you can get ([Click here for the full list | You can get metadata about a particular revision through the <code>rvprop=</code> parameter. Here are some of the things you can get ([[Click here for the full list|mw:API:Revisions#Parameters]]): | ||
* ids: | * ids: | ||
Line 56: | Line 82: | ||
=== Editor metadata === | === Editor metadata === | ||
You can get metadata about a particular editor through the <code>rvprop=</code> parameter. Here are some of the things you can get ([[Click here for the full list|mw:API:Revisions#Parameters]]): | |||
* | * ids: | ||
:* revid: current revision of the page | |||
:* parentid: previous revision of the page | |||
* timestamp: The date and time the revision was made | |||
* user: The username of the editor who made the revision (or their IP address, if they aren't logged in) | |||
* userid: A unique id of the editor | |||
* comment: The edit comment the editor made when they committed the revision | |||
* size: The size of the revision text in bytes. | |||
* content: The revision content. | |||
* tags: Any tags for this revision, such as whether the edit was made on a mobile device | |||
=== Page text and metadata === | === Page text and metadata === | ||
* | * categories a page is in: https://www.mediawiki.org/wiki/API:Categories#Parameters | ||
* | * people who have edited a page: https://www.mediawiki.org/wiki/API:Contributors | ||
* | * images (and audio + video) files on a page: https://www.mediawiki.org/wiki/API:Images | ||
* | * the links on a page: https://www.mediawiki.org/wiki/API:Links | ||
== Resources == | === Resources === | ||
=== API === | ==== API ==== | ||
* [https://www.mediawiki.org/wiki/API:Main_page Main MediaWiki API Documentation] | * [https://www.mediawiki.org/wiki/API:Main_page Main MediaWiki API Documentation] | ||
* [https://en.wikipedia.org/w/api.php Autogenerated API Documentation] | * [https://en.wikipedia.org/w/api.php Autogenerated API Documentation] | ||
Line 85: | Line 108: | ||
* [[Sample API queries]] | * [[Sample API queries]] | ||
=== Research using Wikipedia data === | ==== Research using Wikipedia data ==== | ||
=== Websites that use the MediaWiki API === | ==== Websites that use the MediaWiki API ==== | ||
[[Category:DS4UX (Spring 2016)]] | [[Category:DS4UX (Spring 2016)]] |