# Path: hose_util.py
# def lookup(myjson, k):
#   # return myjson[k]
#   if '.' in k:
#     # jpath path
#     ks = k.split('.')
#     v = myjson
#     for k in ks: v = v.get(k,{})
#     return v or ""
#   return myjson.get(k,"")


from mrjob.job import MRJob
from mrjob.protocol import JSONValueProtocol, PickleProtocol, RawValueProtocol
from hose_util import lookup
import re,os,sys
import json
PA	42	PENNSYLVANIA
RI	44	RHODE ISLAND
SC	45	SOUTH CAROLINA
SD	46	SOUTH DAKOTA
TN	47	TENNESSEE
TX	48	TEXAS
UT	49	UTAH
VA	51	VIRGINIA
VT	50	VERMONT
WA	53	WASHINGTON
WI	55	WISCONSIN
WV	54	WEST VIRGINIA
WY	56	WYOMING
"""

LOWER_48 = LOWER_48.strip().split('\n')
LOWER_48 = [L.split()[0] for L in LOWER_48]
assert len(LOWER_48) == 49  ## lower48 and DC
LOWER_48 = set(LOWER_48)

def filter_lower48(geodict):
    """Returns boolean, whether is OK"""
    s = geodict.get('us_state')
    if not s: return False
    abb = s.get('abbrev')
    return abb in LOWER_48

def filter_tweet(tweet):
    """Returns:  (is_good_tweet, reason)"""


# Path: hose_util.py
# def lookup(myjson, k):
#   # return myjson[k]
#   if '.' in k:
#     # jpath path
#     ks = k.split('.')
#     v = myjson
#     for k in ks: v = v.get(k,{})
#     return v or ""
#   return myjson.get(k,"")


# Path: geo2_pipeline/preproc8/20_message_filter/msgfilters.py
from mrjob.job import MRJob
from mrjob.protocol import JSONValueProtocol, PickleProtocol, RawValueProtocol
from hose_util import lookup
import re,os,sys
import json

PA	42	PENNSYLVANIA
RI	44	RHODE ISLAND
SC	45	SOUTH CAROLINA
SD	46	SOUTH DAKOTA
TN	47	TENNESSEE
TX	48	TEXAS
UT	49	UTAH
VA	51	VIRGINIA
VT	50	VERMONT
WA	53	WASHINGTON
WI	55	WISCONSIN
WV	54	WEST VIRGINIA
WY	56	WYOMING
"""

LOWER_48 = LOWER_48.strip().split('\n')
LOWER_48 = [L.split()[0] for L in LOWER_48]
assert len(LOWER_48) == 49  ## lower48 and DC
LOWER_48 = set(LOWER_48)

def filter_lower48(geodict):
    """Returns boolean, whether is OK"""
    s = geodict.get('us_state')
    if not s: return False
    abb = s.get('abbrev')
    return abb in LOWER_48

def filter_tweet(tweet):
    """Returns:  (is_good_tweet, reason)"""


    source = lookup(tweet, 'source') or ""