Signpost Article Linked Views

Sometimes Signpost articles get linked to by mainstream media (usually tech media). This companion notebook studies what happens when this happens.

In [1]:
from pageviews import PageviewsClient
import urllib
import mwapi
import arrow
import datetime
import json


def viewcounts(article_name, start=None, end=None):
    """
    Fetches the viewcounts.
    """
    article_name = article_name.replace(' ', '_')
    parsed_article_name = urllib.parse.quote(article_name).replace('/', '%2F')
    p = PageviewsClient().article_views("en.wikipedia",
                                        [parsed_article_name],
                                        access="all-access",
                                        # access="users",
                                        granularity="daily",
                                        start=start,
                                        end=end)
    counts = {key: p[key][article_name] for key in p.keys()}
    return [p[key][article_name] for key in sorted(p.keys())]
    # TODO: Fix be pre-padding with 0s if output is below 15 length.
In [2]:
from bokeh.plotting import figure, output_notebook, show
from bokeh.models.tools import HoverTool
import pandas as pd
In [3]:
example_viewcounts = viewcounts("Wikipedia:Wikipedia Signpost/2015-12-09/Op-ed", start="2015121000", end ="2015122900")

output_notebook(hide_banner=True)

p = figure(plot_width=900,
           plot_height=400,
           title='"Wikidata: Knowledge from different points of view"',
           title_text_font_size="18px",
           x_axis_type="datetime"
)

# add a line renderer
p.line(
    [(arrow.get("2015-12-10-00") + datetime.timedelta(days=n)).datetime for n in range(0, 20)],
    example_viewcounts,
    line_width=2,
)

hover = HoverTool()
hover.tooltips = [
#     ("index", "$index"),
#     ("(x,y)", "($x, $y)"),
#     ("radius", "@radius"),
#     ("fill color", "$color[hex, swatch]:fill_color"),
#     ("foo", "@foo"),
#     ("bar", "@bar"),
]

show(p)