Example #1
0
def sync_world_online(world):
    lastchars = None
    while True:
        html, headers = tibiacom.http_get(tibiacom.url.world_online(world))
        newchars = tibiacom.parse.world_online(html=html)[1]
        if lastchars is None:
            print "First read", headers["Date"]
        elif newchars != lastchars:
            print "Page changed", headers["Date"]
        lastchars = newchars
        time.sleep(10)
Example #2
0
 def update_world_online(self, world):
     localStamp = int(time.time())
     html, headers = tibiacom.http_get(tibiacom.world_online_url(world))
     players = tibiacom.parse_world_online(html)
     logging.info("Found %d players on %s", len(players), world)
     serverStamp = to_unixepoch(headers["Date"])
     if abs(localStamp - serverStamp) > 1:
         logging.warning("Page Date %d and localtime %s differ greatly", serverStamp, localStamp)
     #print to_unixepoch(headers["Date"]), int(time.time())
     with self._write_lock():
         for p in players:
             self._update_char(
                     p.name, level=p.level, vocation=p.vocation, online=True,
                     stamp=serverStamp, world=world)
Example #3
0
 def update_world_online(self, world):
     localStamp = int(time.time())
     html, headers = tibiacom.http_get(tibiacom.world_online_url(world))
     players = tibiacom.parse_world_online(html)
     logging.info("Found %d players on %s", len(players), world)
     serverStamp = to_unixepoch(headers["Date"])
     if abs(localStamp - serverStamp) > 1:
         logging.warning("Page Date %d and localtime %s differ greatly",
                         serverStamp, localStamp)
     #print to_unixepoch(headers["Date"]), int(time.time())
     with self._write_lock():
         for p in players:
             self._update_char(p.name,
                               level=p.level,
                               vocation=p.vocation,
                               online=True,
                               stamp=serverStamp,
                               world=world)
Example #4
0
def show_recent_deaths(world):
    queue = Queue.Queue()
    outlock = threading.Lock()
    for char in tibiacom.parse.world_online(tibiacom.http_get(tibiacom.url.world_online(world))[0]):
        if char.vocation != "None":
            queue.put(char)
    def print_recent_deaths():
        while True:
            try:
                char = queue.get_nowait()
                #print "Scanning %s..." % char.name
            except Queue.Empty:
                return
            for death in tibiacom.get_char_info(char.name)["deaths"]:
                if tibiacom.parse.tibia_time_to_unix(death.time) >= time.time() - 3600:
                    with outlock:
                        tibiacom.pretty.pprint_death(death, char.name)
    allthrds = []
    for i in xrange(1):
        t = threading.Thread(target=print_recent_deaths)
        t.start()
        allthrds.append(t)
    for t in allthrds:
        t.join()