def test_getstate(self): state = getstate('187.111.96.65') self.assertEqual('RJ', state) state = getstate('177.166.105.8') self.assertEqual('SP', state) state = getstate('189.9.21.1') self.assertEqual('DF', state)
def get_state(): """ Gets the user Local News Source based on their IP Address :return: a JSON file with the user State and Local News Source """ state = getstate() # DEBUG - Change here to simulate different locations. Comment otherwise. # state = 'TO' if state == 'notfound': ns_title = '' else: ns_local = get_ns('local' + state) ns_title = ns_local.name + '*' d = dict(state=state, ns_title=ns_title) j = json.dumps(d) return j
def get_state(): """ Gets the user Local News Source based on their IP Address :return: a JSON file with the user State and Local News Source """ ip = request.args.get("ip") state = getstate(ip) # DEBUG - Change here to simulate different locations. Comment otherwise. # state = 'TO' if state == "notfound": ns_title = "" else: ns_local = get_ns("local" + state) ns_title = ns_local.name + "*" d = dict(state=state, ns_title=ns_title) j = json.dumps(d) return j