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 [ ]:
# what's in this URL?
In [ ]:
# https://pzwiki.wdka.nl/mw-mediadesign/ ........ magically turns into ........ https://pzwiki.wdka.nl/mediadesign/Main_Page
In [ ]:
# https://pzwiki.wdka.nl/mw-mediadesign/api.php
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 [ ]:
# (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 [ ]: