import pymysql
import os
from pprint import pprint
host = os.environ['MYSQL_HOST']
user = os.environ['MYSQL_USERNAME']
password = os.environ['MYSQL_PASSWORD']
conn = pymysql.connect(
    host=host,
    user=user,
    password=password
)
with conn.cursor() as cur:
    cur.execute('use enwiki_p')
    cur.execute("""
        SELECT *
        FROM revision JOIN page 
            ON page.page_id = revision.rev_page
        WHERE page.page_namespace = 0 AND page.page_title = 'Coffee' 
        ORDER BY revision.rev_timestamp DESC
        LIMIT 10
    """)
    pprint(cur.fetchall())
((766646544,
  604727,
  0,
  b'HTTP→HTTPS for [[The New York Times]]. using [[Project:AWB|AWB]]',
  28903366,
  b'Bender the Bot',
  b'20170221100834',
  1,
  0,
  141099,
  766582344,
  b'32pdamjxy2ei8dgm2wq4sbeg28a1mhn',
  None,
  None,
  604727,
  0,
  b'Coffee',
  b'',
  0,
  0,
  0,
  0.156743757965,
  b'20170224023440',
  b'20170224023457',
  766646544,
  141099,
  b'wikitext'),
 (766582344,
  604727,
  0,
  b'/* Etymology */',
  24382878,
  b'Denniscabrams',
  b'20170221001626',
  0,
  0,
  141096,
  764372475,
  b'2tfx5lm8a01aqjvn6kobatc08imuead',
  None,
  None,
  604727,
  0,
  b'Coffee',
  b'',
  0,
  0,
  0,
  0.156743757965,
  b'20170224023440',
  b'20170224023457',
  766646544,
  141099,
  b'wikitext'),
 (764372475,
  604727,
  0,
  b'Replace dead URL. Other minor reference fixes.',
  17980321,
  b'Nitpicking polish',
  b'20170208153334',
  1,
  0,
  141097,
  762313184,
  b'bw2s8nmyp6g72s0uniw8ciwib733wjp',
  None,
  None,
  604727,
  0,
  b'Coffee',
  b'',
  0,
  0,
  0,
  0.156743757965,
  b'20170224023440',
  b'20170224023457',
  766646544,
  141099,
  b'wikitext'),
 (762313184,
  604727,
  0,
  b'/* External links */',
  26218364,
  b'Neurorebel',
  b'20170128003539',
  0,
  0,
  141219,
  762311897,
  b'60heopjpzh32qzdyyhrmcnzhhe8dz19',
  None,
  None,
  604727,
  0,
  b'Coffee',
  b'',
  0,
  0,
  0,
  0.156743757965,
  b'20170224023440',
  b'20170224023457',
  766646544,
  141099,
  b'wikitext'),
 (762311897,
  604727,
  0,
  b'/* External links */',
  26218364,
  b'Neurorebel',
  b'20170128002601',
  0,
  0,
  141161,
  762311794,
  b'nnpggfjumhncbcywwcq6bx4box6poow',
  None,
  None,
  604727,
  0,
  b'Coffee',
  b'',
  0,
  0,
  0,
  0.156743757965,
  b'20170224023440',
  b'20170224023457',
  766646544,
  141099,
  b'wikitext'),
 (762311794,
  604727,
  0,
  b'/* External links */',
  26218364,
  b'Neurorebel',
  b'20170128002513',
  0,
  0,
  141161,
  762308903,
  b'nx6fhkck1bchpqbpqcs5nsva88usub3',
  None,
  None,
  604727,
  0,
  b'Coffee',
  b'',
  0,
  0,
  0,
  0.156743757965,
  b'20170224023440',
  b'20170224023457',
  766646544,
  141099,
  b'wikitext'),
 (762308903,
  604727,
  0,
  b'/* External links */',
  26218364,
  b'Neurorebel',
  b'20170128000312',
  0,
  0,
  141154,
  761483844,
  b'p2oa5euy5ugacfaeh2egadzgmnk2o90',
  None,
  None,
  604727,
  0,
  b'Coffee',
  b'',
  0,
  0,
  0,
  0.156743757965,
  b'20170224023440',
  b'20170224023457',
  766646544,
  141099,
  b'wikitext'),
 (761483844,
  604727,
  0,
  b'/* Production */ link to WP articles on coffee production by country',
  5171218,
  b'Farolif',
  b'20170123054428',
  0,
  0,
  141186,
  761465946,
  b'ozvg1mv36g0370jpwr9sl05j5yg5cwy',
  None,
  None,
  604727,
  0,
  b'Coffee',
  b'',
  0,
  0,
  0,
  0.156743757965,
  b'20170224023440',
  b'20170224023457',
  766646544,
  141099,
  b'wikitext'),
 (761465946,
  604727,
  0,
  b'/* Cancer */',
  16473280,
  b'TylerDurden8823',
  b'20170123034146',
  1,
  0,
  140646,
  761465763,
  b'33v9g98ncgx49bkcltxg2f13kef8epd',
  None,
  None,
  604727,
  0,
  b'Coffee',
  b'',
  0,
  0,
  0,
  0.156743757965,
  b'20170224023440',
  b'20170224023457',
  766646544,
  141099,
  b'wikitext'),
 (761465763,
  604727,
  0,
  b'WL MI.',
  16473280,
  b'TylerDurden8823',
  b'20170123034026',
  1,
  0,
  140643,
  761461009,
  b'cp2tktl7r3uxov2fqi86zyvfez8ttta',
  None,
  None,
  604727,
  0,
  b'Coffee',
  b'',
  0,
  0,
  0,
  0.156743757965,
  b'20170224023440',
  b'20170224023457',
  766646544,
  141099,
  b'wikitext'))