Skip to content

Instantly share code, notes, and snippets.

@halfak
Created March 17, 2020 14:33
Show Gist options
  • Select an option

  • Save halfak/baa839823ecc0fa7d56bbc6d13975857 to your computer and use it in GitHub Desktop.

Select an option

Save halfak/baa839823ecc0fa7d56bbc6d13975857 to your computer and use it in GitHub Desktop.
import time
import mwapi
import textstat
session = mwapi.Session("https://en.wikipedia.org", user_agent="ahalfaker@wikimedia.org")
doc = session.get(action='query', prop='revisions', rvprop='content', titles='Alan Turing', rvslots="main", formatversion=2)
text = doc['query']['pages'][0]['revisions'][0]['slots']['main']['content']
start = time.time()
print("flesch_reading_ease", textstat.flesch_reading_ease(text))
print("Processing took {0} seconds".format(time.time() - start))
start = time.time()
print("flesch_reading_ease", textstat.flesch_reading_ease(text))
print("Processing took {0} seconds".format(time.time() - start))
$ python demo_flesch_reading_ease.py
flesch_reading_ease -31.94
Processing took 0.5710229873657227 seconds
flesch_reading_ease -31.94
Processing took 1.3828277587890625e-05 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment