def run(self): ex = Extractor() with open(os.path.expanduser('~/.elc/main/chat_log.txt')) as f: line = f.readline() while line != "": ex.feed(line.strip()) line = f.readline() while True: line = f.readline() while line != "": if ex.feed(line.strip()): log.info("changed location %s, '%s'" % (ex.loc, ex.map_name)) if self.window: #~ log.debug("posting event") evt = LocationChangedEvent(map_name=ex.map_name, loc=ex.loc) #~ evt = LocationChangedEvent() wx.PostEvent(self.window, evt) line = f.readline() log.debug("Sleeping...") sleep(1) self.x = True print "thread!"
def test_dp_sto(self): ex = Extractor() self.assertTrue(ex.feed("Welcome to the Desert Pines storage")) self.assertTrue(ex.feed("You are in [98,38]")) self.assertEqual("Desert Pines storage", ex.map_name) self.assertEqual( (98,38), ex.loc)
def test_welcome(self): ex = Extractor() self.assertTrue(ex.feed("Welcome to the Desert Pines storage")) self.assertEqual("Desert Pines storage", ex.map_name)
def test_white_stone(self): ex = Extractor() self.assertTrue(ex.feed("Welcome to White Stone, Lakeside Village")) self.assertEqual("White Stone, Lakeside Village", ex.map_name)
def test_portland_cave(self): ex = Extractor() self.assertTrue(ex.feed("You are in Portland [169,369]")) self.assertEqual("Portland", ex.map_name) self.assertEqual( (169,369), ex.loc)
def test_exit_dp_sto(self): ex = Extractor() self.assertTrue(ex.feed("You are in Desert Pines [166,100]")) self.assertEqual("Desert Pines", ex.map_name) self.assertEqual( (166,100), ex.loc)
#~ print "-->" + str(subitem) def find_location_obj(map_name, loc): for item in all_nodes: p = item.payload if p.map_name() == map_name and p.loc_touple() == loc: return item raise Exception("not found") import os from get_location import Extractor ex = Extractor() with open(os.path.expanduser('~/.elc/main/chat_log.txt')) as f: for line in f: ex.feed(line.strip()) print "Your are in '%s' at %s" % (ex.map_name, ex.loc) near_locations = [] for item in all_nodes: if item.payload.map_name() == ex.map_name: #~ print item d = distance(item.payload.loc_touple(), ex.loc) near_locations.append((d, item)) near_locations.sort() print "\nnear_locations" pprint(near_locations) where_am_i = near_locations[0][1] print "\nnear_location: %s" % where_am_i