def updateFile(self, fileId, http, currentBlog): forced = self.request.get('force') req = service.files().get(fileId=fileId) item = req.execute(http) post = Posts.GetPostById(fileId, currentBlog) if post and post.postid != fileId: logging.error('No post!') post = None if not 'title' in item and 'modifiedDate' in item and 'exportLinks' in item: return self.error(404) title = item['title'] lastmodified = item['modifiedDate'] if post and post.lastmodified == lastmodified and not forced: return Redirect(self, 'No modifcation needed!', '/get?id=%s' % fileId) exportLinks = item['exportLinks'] htmlResp, htmlContent = http.request(exportLinks['text/html']) textResp, textContent = http.request(exportLinks['text/plain']) if textResp.status != 200 or htmlResp.status != 200: return self.error(404) htmlContent = unicode(htmlContent, errors='ignore') textContent = unicode(textContent, errors='ignore') content = contentparser.analyze(textContent, htmlContent) text = MarkdownText(content) snippet = '' pic = '/r/defaults/%d.jpg' % randint(1,3) if post: post.text = text post.lastmodified = lastmodified else: post = Posts(title=title, text=text, pic=pic, snippet=snippet, lastmodified=lastmodified, postid=fileId, blog=currentBlog.subdomain, visible=False) post.put() Redirect(self, 'Loading page.', '/get?id=%s' % fileId)