def receive(self, message): plaintext_bodies = message.bodies('text/plain') subject = message.subject body = "" for plaintext_body in plaintext_bodies: body = body + plaintext_body[1].decode() link, summary, tags = BuildLinkFromEmail.parse_body(body) if link != None: Link.save_link(subject, link, summary, tags)
def migrate(): LinkDoc.deleteAllInIndex() q = Link.query() links = q.fetch(65535) for link in links: title = link.title url = link.url tags = link.tags body = link.body link.key.delete() LinkDoc.save_link(title, url, body, tags)
def update_link(id): link = L.get_by_id(id) if link == None: return jsonify(success=False, message="No link exisit by id: "+str(id)) title = request.form.get('title') body = request.form.get('body') unread = request.form.get('unread', type=bool) tags = request.form.getlist('tags') clicks = int(request.form.get('clicks')) if title != link.title or body != link.body or tags != link.tags: Link.save_link(title, link.url, body, tags, clicks, unread) elif unread != link.unread or clicks != link.clicks: link.unread = unread link.clicks = clicks link.put() return jsonify(success=True, size=1, data=link)
def search_link(): query = request.args.get('query') if not query: return jsonify(size=0, data=[]) query_string = to_query_string(query) if query_string == '': return jsonify(size=0, data=[]) ids = Link.search(query_string) if len(ids): links = map(lambda x:L.get_by_id(int(x)), ids) links = [l.to_dict() for l in links] return jsonify(size = len(links), data=links) else: return jsonify(size=0, data=[])
def delete_link(id): Link.delete_link(id)