from sqlalchemy import create_engine
import sys, os
import pandas as pd

constr = 'mysql+pymysql://{user}:{pwd}@{host}'.format(user=os.environ['MYSQL_USERNAME'],
con = create_engine(constr)

df = pd.read_sql('select * from plwiki_p.logging limit 10', con)
import mwapi
session = mwapi.Session('') #TODO add user agent
Sending requests with default User-Agent.  Set 'user_agent' on mwapi.Session to quiet this message.
print(session.get(action='query', meta='userinfo'))
{'query': {'userinfo': {'anon': '', 'name': 'Jtmorgan', 'id': 0}},
 'batchcomplete': ''}
{'batchcomplete': '', 'query': {'userinfo': {'id': 0, 'name': '', 'anon': ''}}}
{'query': {'userinfo': {'anon': '', 'name': 'Jtmorgan', 'id': 0}},
 'batchcomplete': ''}
import mwviews
from mwviews.api import PageviewsClient
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-5-4d77827dff32> in <module>()
----> 1 import mwviews
      2 from mwviews.api import PageviewsClient

ModuleNotFoundError: No module named 'mwviews'
import wdqs
import csv
import encoding_fix
import json
from operator import itemgetter
import requests
import time

#load in the JSON file we created with
with open("data/residential_permits_2010-2016.json") as json_infile:
    bp_api_data = json.load(json_infile)

Example query:,-73.961452&result_type=street_address
#create an empty dictionary that will hold our per-neighborhood counts
permits_by_neighborhood = {}

#go through each permit record and get the neighborhood for each address.
for x in bp_api_data:
#     print(x)
    #we're only interested in MULTIFAMILY construction right now, not SINGLE FAMILY / DUPLEX
    if x['category'] == "MULTIFAMILY":
        # if a row doesn't contain lat/long, 
        # OR if Google Maps API can't find a neighborhood for a given lat/long, 
        # we're going to skip it
            #add the city and state to the end of each address before querying the Google Maps API
            gmaps_api_params = {'latlng' : x['latitude'] + "," + x["longitude"]}
            gmaps_api_req = requests.get("", params=gmaps_api_params)
            # save the content of the request to a Python dict and start parsing it
            gmaps_api_data = gmaps_api_req.json()
            neighborhood = gmaps_api_data['results'][0]['address_components'][2]['long_name']
            if neighborhood in permits_by_neighborhood:
                permits_by_neighborhood[neighborhood] += 1
                permits_by_neighborhood[neighborhood] = 1
        #slow down our API requests, to avoid getting blocked by Google    
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-7-921e36de1f67> in <module>()
      1 import csv
----> 2 import encoding_fix
      3 import json
      4 from operator import itemgetter
      5 import requests

ModuleNotFoundError: No module named 'encoding_fix'