You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10 KiB

Today's iPython errors

In [ ]:
# to hide the warning for today
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
In [ ]:
 
In [ ]:
 

MediaWiki API

In [ ]:
# Let's start with an API reqeust example, using the PZI wiki:
In [65]:
# When you visit .... https://pzwiki.wdka.nl/mw-mediadesign/ ........ the URL magically turns into ........ https://pzwiki.wdka.nl/mediadesign/Main_Page
# This is probably something configured on the server (which is the XPUB XVM server, the wiki is installed there).
In [67]:
# How to access the API?

# Visit in the browser: 

https://pzwiki.wdka.nl/mw-mediadesign/api.php (This is the main access point of the API of the PZI wiki.)

https://pzwiki.wdka.nl/mw-mediadesign/api.php?action=query&titles=Main%20page&format=json (This is an example of an API request.)

In [64]:
# What's in this URL?
In [ ]:
# api.php 
In [ ]:
# ?
In [ ]:
# ?action=query
In [ ]:
# &
In [ ]:
# &titles=Main%page
In [ ]:
# &format=json

Documentation page of the MediaWiki API: https://pzwiki.wdka.nl/mw-mediadesign/api.php

In [ ]:
 

Dérive in the API

In [ ]:
# Wander around in the documentation page, edit the URL, make a couple requests!
In [68]:
# Try to use the actions: "query" and "parse". 
# We will focus on these two today.
In [ ]:
# (paste your requests on the pad)
In [ ]:
 
In [ ]:
 
In [ ]:
 

Use the API in a Notebook

In [ ]:
# Using urllib & json
In [ ]:
import urllib
import json
In [ ]:
url = 'https://pzwiki.wdka.nl/mw-mediadesign/api.php?action=query&titles=Main%20page&format=json'
In [ ]:
request = urllib.request.urlopen(url).read()
In [ ]:
data = json.loads(request)
In [ ]:
data
In [ ]:
 
In [ ]:
# Display JSON in Notebooks nicely, using iPython
In [ ]:
from IPython.display import JSON
In [ ]:
JSON(data)
In [ ]:
 
In [ ]:
 

Try different query and parse actions

In [ ]:
# Let's write the URL in two parts:
# - main domain
# - API request
In [ ]:
wiki = 'https://pzwiki.wdka.nl/mw-mediadesign'
In [ ]:
query = f'{ wiki }/api.php?action=query&titles=Category:Situationist_Times&format=json'
In [ ]:
parse = f'{ wiki }/api.php?action=parse&page=Category:Situationist_Times&format=json'
In [ ]:
querylinks = f'{ wiki }/api.php?action=query&prop=links&titles=Main%20Page'
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
# make the request here in the notebook
request = urllib.request.urlopen(url).read()
data = json.loads(request)
In [ ]:
 

Save HTML as files

In [ ]:
# try to use .open() and .write() to open and write the HTML to a file
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 

$ cp to /var/www/html/PrototypingTimes/

In [ ]:
# Let's publish our HTML files
In [ ]:
# ! cp ANYFILE /var/www/html/PrototypingTimes
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: