import pywikibot
import pandas as pd

import matplotlib.pyplot as plt
%matplotlib inline
site = pywikibot.Site('en', 'wikipedia')  # any site will work, this is just an example
page = pywikibot.Page(site, 'Douglas Adams')
# page?
item = pywikibot.ItemPage.fromPage(page)
item?
repo = site.data_repository()
repo
DataSite("wikidata", "wikidata")
ser=pd.Series(item.sitelinks)
ser.head()
arwiki               دوغلاس آدمز
arzwiki             دوجلاس ادامز
astwiki            Douglas Adams
azwiki              Duqlas Adams
azwikiquote    Duqlas Noel Adams
dtype: object
if "P31" in item.claims:
    print (item.claims['P31'][0].getTarget())
[[wikidata:Q5]]
item.claims?
item_Berlin = pywikibot.ItemPage.fromPage(pywikibot.Page(site,'Berlin'))
item_Berlin.claims['P625'][0].getTarget()
Coordinate(lat=52.516666666667, lon=13.383333333333, globe=earth)
for i in item_Berlin.claims['P17']:  #Object with border to Berlin
    print (i.getTarget())
[[wikidata:Q183]]
[[wikidata:Q16957]]
[[wikidata:Q55300]]
[[wikidata:Q7318]]
[[wikidata:Q41304]]
[[wikidata:Q43287]]
[[wikidata:Q150981]]
[[wikidata:Q27306]]
[[wikidata:Q157367]]
[[wikidata:Q148499]]
for i in item_Berlin.claims['P625']:
    print (i.getTarget())
{
    "altitude": null,
    "globe": "http://www.wikidata.org/entity/Q2",
    "latitude": 52.516666666667,
    "longitude": 13.383333333333,
    "precision": 0.016666666666667
}
plt.title('Minimalistic Map of Berlin')
plt.plot(item_Berlin.claims['P625'][0].getTarget().lon,item_Berlin.claims['P625'][0].getTarget().lat,"x");
item_Berlin.claims['P625'][0].getTarget().lat
52.516666666667
import mplleaflet
fig=plt.figure(figsize=(17,10))

plt.plot(item_Berlin.claims['P625'][0].getTarget().lon,item_Berlin.claims['P625'][0].getTarget().lat,"o");

mplleaflet.display(fig=fig)
import ipyleaflet as ll
!wget "https://raw.githubusercontent.com/ellisonbg/ipyleaflet/master/examples/europe_110.geo.json"
--2016-12-14 12:36:24--  https://raw.githubusercontent.com/ellisonbg/ipyleaflet/master/examples/europe_110.geo.json
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.32.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.32.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 117900 (115K) [text/plain]
Saving to: ‘europe_110.geo.json.1’

europe_110.geo.json 100%[=====================>] 115.14K  --.-KB/s   in 0.007s 

2016-12-14 12:36:25 (16.6 MB/s) - ‘europe_110.geo.json.1’ saved [117900/117900]

import json
import sys, os, time

map = ll.Map(center=[53.88,27.45], zoom=4)

with open('./europe_110.geo.json') as f:
    data = json.load(f)

for feature in data['features']:
    feature['properties']['style'] = {
        'color': 'grey',
        'weight': 1,
        'fillColor': 'grey',
        'fillOpacity': 0.5
    }

layer = ll.GeoJSON(data=data, hover_style={'fillColor': 'red'})

def hover_handler(event=None, id=None, properties=None):
    sys.stdout.write("\r" + properties['geounit'])
    sys.stdout.flush()
    
layer.on_hover(hover_handler)
    
map.add_layer(layer)

map
Germany
!dir
Parse01.ipynb	database01.ipynb     pydata01.ipynb
Untitled.ipynb	europe_110.geo.json  untitled.txt