import tabula
import pandas as pd

import requests

response = requests.get('https://eml.berkeley.edu/~dromer/papers/MRW_QJE1992.pdf')

with open('./mrw-1992.pdf', 'wb') as f:
  f.write(response.content)

t1 = tabula.read_pdf('./mrw-1992.pdf', pages=28, silent=True)
t1 = t1[0]
t1.rename(columns={'0':'O', '1960':'GDP_1960', '1985':'GDP_1985', 'GDP':'g(GDP)', 'age pop':'g(POP)', 'Unnamed: 0':'I/Y', 'Unnamed: 1':'SCHOOL'}, inplace=True)

t2 = tabula.read_pdf('./mrw-1992.pdf', pages=29, silent=True)
t2 = t2[0]
t2.rename(columns={'0':'O', '1960':'GDP_1960', '1985':'GDP_1985', 'GDP':'g(GDP)', 'age pop':'g(POP)', 'Unnamed: 0':'I/Y', 'Unnamed: 1':'SCHOOL'}, inplace=True)

t3 = tabula.read_pdf('./mrw-1992.pdf',pages=30,silent=True, columns=[68, 150, 160, 170, 178, 205, 233, 251, 285, 306], guess=False)
t3 = t3[0][6:43]
t3.rename(columns={'436':'Number', 'QUARTERL':'Country', 'Y':'N', 'JO':'I', 'U':'O', 'RNAL':'GDP_1960', 'OF ECO':'GDP_1985', 'NOM':'g(GDP)', 'ICS':'g(POP)','Unnamed: 0':'I/Y', 'Unnamed: 1':'SCHOOL'}, inplace=True)

mrwdata = pd.concat([t1,t2,t3], ignore_index=True)
