def post(self): """ /api/item, POST, create item 表单字段: url, author, title, content """ p = Entry() p.url = self.request.get('tUrl') p.author = self.request.get('tAuthor') p.title = self.request.get('tTitle') p.content = self.request.get('tContent') p.tags = self.request.get('tTags').split(',') p.put(); # save self.response.headers['Content-Type'] = 'application/json' self.response.out.write('{ "success":true, "id":%s }' % p.key().id())
def post(self): #表单字段: url, author, title, content, allow_sendto_kindle bSendIt = self.request.get('bSendIt') p = Entry() p.url = self.request.get('tUrl') p.author = self.request.get('tAuthor') p.title = self.request.get('tTitle') p.content = self.request.get('tContent') p.tags = self.request.get('tTags').split(',') p.put(); # save #send to kindle if bSendIt: common.add_task_sendmail(p.key().id()); return self.redirect('/list/1')
def handle_entry(self, message): entry = Entry(author='Julian') raw, entry.content = self.get_content(message) if entry.content is None: logging.error("Failed to find message body") logging.error(message) return matches = re.search("diaryentry(\d+)", raw) if matches is None: logging.error("received mail that wasn't a diary entry") logging.error(raw) return entry.date = datetime.date.fromtimestamp(int(matches.group(1))) entry.put() num_attachments = 0 # fall back to raw mail message for attachment parsing for part in message.original.walk(): content_type = part.get_content_type() if content_type not in ["text/plain", "text/html", "multipart/mixed", "multipart/alternative"]: attachment = Attachment(name=part.get_param("name"), content_type=content_type) # store attachment in blobstore bucket = '/infinite-diary.appspot.com' filename = os.path.join(bucket, 'attachments', time.strftime('%Y-%m-%d_%H-%M'), str(num_attachments)) with gcs.open(filename, 'w') as f: f.write(base64.b64decode(part.get_payload())) attachment.content = blobstore.create_gs_key('/gs' + filename) attachment.entry = entry.key() attachment.thumbnail = images.get_serving_url(attachment.content, size=400) attachment.put() num_attachments += 1