def atualizaLink(): if request.get_json() is None: abort(http.HTTPStatus.PRECONDITION_REQUIRED) try: body = request.get_json() obj = Link() obj.dictToLink(body) obj = service.update(obj) return jsonify(obj.linkToJson()) except ModuleNotFoundError: abort(http.HTTPStatus.NO_CONTENT) except Exception: abort(http.HTTPStatus.INTERNAL_SERVER_ERROR)
def removerdoc(): if request.get_json() is None: abort(http.HTTPStatus.PRECONDITION_REQUIRED) try: body = request.get_json() obj = Link() obj.dictToLink(body) service.findById(obj.id) if (obj is None): raise ModuleNotFoundError('Não encontrado') obj = service.remove(obj) return jsonify(obj.linkToJson()) except ModuleNotFoundError: abort(http.HTTPStatus.BAD_REQUEST) except Exception: abort(http.HTTPStatus.BAD_REQUEST)
def loadOrNewLink(self, url, documento): link = ls.findByUrl(url) if link is None: link = Link() link.url = url host = hs.findByUrl(url) link.host = host link.host_id = host.id link.ultimaColeta = datetime.datetime.now() link = ls.save(link) else: link.ultimaColeta = datetime.datetime.now() link = ls.update(link) return link
def atualizaUltimaColetaSementes(): if request.get_json() is None: abort(http.HTTPStatus.PRECONDITION_REQUIRED) try: body = request.get_json() objn = Link() obj = Link() objn.dictToLink(body) obj = service.findById(objn.id) if (obj is None): raise ModuleNotFoundError('não encontrado.') obj.ultimaColeta = objn.ultimaColeta obj = service.update(obj) return jsonify(obj.linkToJson()) except ModuleNotFoundError: abort(http.HTTPStatus.NO_CONTENT) except Exception: abort(http.HTTPStatus.INTERNAL_SERVER_ERROR)
def inserirSemente(self, url): link = Link() linkOld = Link() linkOld = self.findByUrl(url) if linkOld is None: host = Host() host = hs.createUpdateHost(url) link.host_id = host.id link.host = host link.url = url link = self.save(link) else: link = linkOld return link