def put_linha(self, id, deleted, info, pontos, hashes): """Atualiza uma linha no banco (incluindo delete) e anula seu cache. O cache dos hashes não é atualizado (supõe-se que eles também serão atualizados no final). Retorna mensagem consumível pelo sptscraper""" try: id = int(id) self.cache.delete("info_por_linha_id_%s" % id) if deleted == "true": linha = Linha.all().filter("id =", id).fetch(1) if linha: linha.delete() return "OK LINHA DELETE %s " % id else: return "OK LINHA DELETE %s (NAO EXISTIA)" % id else: linha = Linha.all().filter("id =", id).fetch(1) if linha: linha = linha[0] linha.info = info linha.pontos = pontos linha.hashes = hashes else: linha = Linha(id=id, info=info, pontos=pontos, hashes=hashes) linha.put() return "OK LINHA UPLOAD %s " % id except: return "ERRO LINHA: %s" % sys.exc_info()[1]
def put_linha(self, id, deleted, info, pontos, hashes): """Atualiza uma linha no banco (incluindo delete) e anula seu cache. O cache dos hashes não é atualizado (supõe-se que eles também serão atualizados no final). Retorna mensagem consumível pelo sptscraper""" try: id = int(id) self.cache.delete("info_por_linha_id_%s" % id) if deleted == "true": linha = Linha.all().filter("id =", id).fetch(1) if linha: db.delete(linha) return "OK LINHA DELETE %s " % id else: return "OK LINHA DELETE %s (NAO EXISTIA)" % id else: linha = Linha.all().filter("id =", id).fetch(1) if linha: linha = linha[0] linha.info = info linha.pontos = pontos linha.hashes = hashes else: linha = Linha(id = id, info = info, pontos = pontos, hashes = hashes) linha.put() return "OK LINHA UPLOAD %s " % id except: return "ERRO LINHA: %s" % sys.exc_info()[1]
def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Apagando pontos...') while Ponto.all().fetch(1): db.delete(Ponto.all().fetch(100)) self.response.out.write('Apagando linhas...') while Linha.all().fetch(1): db.delete(Linha.all().fetch(100)) self.response.out.write('Ok')
def get(self): self.response.headers['Content-Type'] = 'text/html' if self.request.get("hashes"): for hash in Hash.all(): self.response.out.write('<a href="/cachehash?hash=%s">%s</a><br/>' % (hash.hash, hash.hash)) else: for linha in Linha.all(): self.response.out.write('<a href="/cachelinha?key=%s">%s</a><br/>' % (str(linha.key()), linha.nome))
def HandleEntity(self, entity): linha = Linha.all().filter("nome =", entity["nome"]).fetch(1)[0] ponto = Ponto(ordem=entity["ordem"], linha=linha, lat=entity["lat"], lng=entity["lng"]) pontosAnt = Ponto.all().filter("linha =", linha).filter("ordem =", ponto.ordem - 1).fetch(1) if pontosAnt: pontoAnt = pontosAnt[0] ponto.setNearhash(pontoAnt) ponto.put() return None
def get_info_hashes_linha(self, linha_id): """Retorna objeto JSON com as infos gerais e hashes da linha""" chave_memcache = "info_por_linha_id_%s" % linha_id linha = self.cache.get(chave_memcache) if linha is None: result = Linha.all().filter("id =", int(linha_id)).fetch(1) if result: linha = '{"id":%s,"info":%s,"hashes":%s}' % (linha_id, result[0].info,result[0].hashes) self.cache.add(chave_memcache, linha) return linha
def get_pontos_linha(self, linha_id): """Retorna objeto JSON com os pontos do trajeto para cada dia e sentido""" chave_memcache = "pontos_por_linha_id_%s" % linha_id pontos = self.cache.get(chave_memcache) if pontos is None: result = Linha.all().filter("id =", int(linha_id)).fetch(1) if result: pontos = result[0].pontos self.cache.add(chave_memcache, pontos) return pontos
def get_pontos_linha(self, linha_id): """Retorna objeto JSON com os pontos do trajeto para cada dia e sentido""" chave_memcache = "pontos_por_linha_id_%s" % linha_id pontos = self.cache.get(chave_memcache) if pontos is None: result = Linha.all().filter("id =", int(linha_id)).fetch(1) if result: pontos = result[0].pontos self.cache.add(chave_memcache, pontos) return pontos
def get_info_hashes_linha(self, linha_id): """Retorna objeto JSON com as infos gerais e hashes da linha""" chave_memcache = "info_por_linha_id_%s" % linha_id linha = self.cache.get(chave_memcache) if linha is None: result = Linha.all().filter("id =", int(linha_id)).fetch(1) if result: linha = '{"id":%s,"info":%s,"hashes":%s}' % ( linha_id, result[0].info, result[0].hashes) self.cache.add(chave_memcache, linha) return linha
def HandleEntity(self, entity): for linha in Linha.all().filter("nome =", entity["nome"]).fetch(999): for ponto in linha.pontos: ponto.delete() linha.delete() return entity
def get(self): self.response.headers['Content-Type'] = 'text/html' for linha in Linha.all(): self.response.out.write('<a href="/gerahash?key=%s">%s</a><br/>' % (str(linha.key()), linha.nome))