def QueryAPI(catname): params = {'action':'query','list':'categorymembers','format':'json','cmtitle':'Category:'+catname, 'cmprop':'title','cmnamespace':'1','cmlimit':'500'} api = MWApi('http://en.wikipedia.org') while True: data = api.get(params) for page in data['query']['categorymembers']: print page['title'] if data.has_key('query-continue'): params['cmcontinue'] = data['query-continue']['categorymembers']['cmcontinue'] else: break
def login(username, password): try: mw = MWApi(host=app.config['MEDIAWIKI']['host'], api_path=app.config['MEDIAWIKI']['api']) mw.login(username, password) mw.populateTokens() user = User(username, password, edittoken=mw.tokens['edittoken'], watchtoken=mw.tokens['watchtoken']) session['username'] = user.username session['password'] = user.password return mw except: raise LoginFailedError("Unable to Login")
from db import * from flask import * import json from werkzeug.contrib.cache import MemcachedCache from werkzeug.contrib.atom import AtomFeed from mwapi import MWApi app = Flask(__name__) app.debug = True setup_app(app) cache = MemcachedCache(['127.0.0.1:11211']) api = MWApi("http://en.wikipedia.org") @app.route('/issues') def first_issues(): issues_data = cache.get("all_issues") if not issues_data: issues = Issue.query.order_by(Issue.date.desc()).all() data = [issue.serialize() for issue in issues] issues_data = json.dumps(data) cache.set("all_issues", issues_data) return (issues_data, 200, {'Content-Type': 'application/json'}) @app.route('/issues/<int:offset>') def issues(offset): # Stub, here because I'm lazy
def session(self, url: str) -> MWApi: sess = MWApi(url, "/api.php") sess.login(self._username, self._password) return sess
from datetime import datetime from dateutil import parser from mwapi import MWApi import codecs import requests import urllib2 import re from flask import Flask from db import * START_YEAR = 2005 CUR_YEAR = datetime.now().year api = MWApi('http://en.wikipedia.org') def content_for_title(title): title = urllib2.unquote(title) data = api.get(action='parse', page=title, redirects=1, prop='text')['parse'] text = data['text']['*'] return text def get_subpages(prefix, namespace): pages = api.get(action='query', list='allpages', apprefix=prefix, apnamespace=namespace,