Toggle navigation
Home
New Query
Recent Queries
Discuss
Database tables
Database names
MediaWiki
Wikibase
Replicas browser and optimizer
Login
History
Fork
This query is marked as a draft
This query has been published
by
Don brito
.
Toggle Highlighting
SQL
%matplotlib notebook import csv import json import time import sys import requests import mwapi import mwtypes import pandas import seaborn session = mwapi.Session("https://en.wikipedia.org", user_agent="diego@wikimedia.org -- Tools demo") WEIGHTS = {'Stub': 1, 'Start': 2, 'C': 3, 'B': 4, 'GA': 5, 'FA': 6} def score2sum(score_doc): weighted_sum = 0 for cl, proba in score_doc['probability'].items(): weighted_sum += WEIGHTS[cl] * proba return weighted_sum def fetch_wp10_score(rev_id): response = requests.get('https://ores.wikimedia.org/v3/scores/enwiki/{0}/wp10'.format(rev_id)) return response.json()['enwiki']['scores'][str(rev_id)]['wp10']['score'] def fetch_historical_scores(page_name): historical_scores = [] for response_doc in session.get(action='query', prop='revisions', titles=page_name, rvprop=['ids', 'timestamp'], rvlimit=100, rvdir="newer", formatversion=2, continuation=True): for rev_doc in response_doc['query']['pages'][0]['revisions']: rev_id = rev_doc['revid'] timestamp = rev_doc['timestamp'] weighted_sum = score2sum(fetch_wp10_score(rev_id)) historical_scores.append({'rev_id': rev_id, 'timestamp': timestamp, 'weighted_sum': weighted_sum}) sys.stderr.write(".") sys.stderr.flush() sys.stderr.write("\n") return historical_scores
By running queries you agree to the
Cloud Services Terms of Use
and you irrevocably agree to release your SQL under
CC0 License
.
Submit Query
Stop Query
All SQL code is licensed under
CC0 License
.
Checking query status...