本文整理汇总了Python中post.Post类的典型用法代码示例。如果您正苦于以下问题:Python Post类的具体用法?Python Post怎么用?Python Post使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Post类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_site
def update_site(self):
"""Updates only the static pages"""
files = os.listdir(self.datadir)
for f in files:
if f[0] != '.': # leave out hidden files
post = Post(self.datadir+f)
post.write(self.posts, self.tags)
示例2: print_post
def print_post(args):
if 'all' in args.postid:
posts = Post.load()
else:
try:
ids = [int(x) for x in args.postid]
except ValueError:
print('Post IDs should be numbers')
return
posts = Post.load(ids)
if not len(posts):
print('Post ID(s) not found: {}'.format(' '.join(args.postid)))
return
if args.s:
posts = order_by_date(posts)
for postid in posts.keys():
if len(posts[postid]['body']) > 74:
body = '\n '.join(trunc(posts[postid]['body'], 74))
else:
body = posts[postid]['body']
print('Title: {}\nPost ID: {}, last modification date: {}\nBody: {}'
.format(posts[postid]['title'],
postid,
posts[postid]['date'],
body))
print('-' * 80)
示例3: main
def main():
# READ TEMPATE HTML FILES
base_html = open("templates/base.html")
post_html = open("templates/post.html")
# CREATE PAGE
page = base_html.readlines()
posts = []
# OPEN POST TXT FILES
postfiles = [ f for f in listdir("posts") if isfile(join("posts",f)) ]
for postfile in postfiles:
temp = open("posts/" + postfile, "r")
postlines = temp.readlines()
post_obj = Post(postlines[0], postlines[1], postlines[2:])
posts.append("".join(post_obj.render(post_html)))
post_html.seek(0)
temp.close()
# INSERT POSTS INTO PAGE
for i in range(len(page)):
page[i] = page[i].replace("[[posts]]", "\n\n".join(posts))
# WRITE PAGE TO OUTPUT HTML FILE
final = open("output/final.html", "a+")
final.write("".join(page))
# CLOSE FILES
base_html.close()
post_html.close()
示例4: __init__
def __init__(self, src_path, exclude=() ):
post_list = []
for file_path in os.listdir(src_path):
if not file_path.endswith('.py') or file_path in SOURCE_EXCLUDE:
# TODO convert to regex matching
continue
full_path = os.path.join(src_path, file_path)
try:
post = Post(full_path)
post_list.append(post)
except Exception as e:
import traceback
traceback.print_exc()
print 'Error creating Post from '+str(full_path)+':'+str(e)
continue
self.posts = sorted(post_list, key=lambda p: p.updated)
self._check_monotonic()
self._resolve_links()
for post in self.posts:
errors = post.get_errors()
for error in errors:
print 'Error in',post.filename,'on line',str(error.line)+': ',error.message,
if error.text: print '('+error.text+')'
print
示例5: receive
def receive(self, message):
post = Post()
html_bodies = message.bodies('text/html')
img_links = []
video_links = []
for content_type, body in html_bodies:
decoded_body = body.decode()
img_links.extend(self.find_image_links(decoded_body))
video_links.extend(self.find_video_links(decoded_body))
if hasattr(message, "attachments") and message.attachments:
post.attachments = []
for attachment in message.attachments:
post.attachments.append(db.Blob(attachment[1].decode()))
plaintext_bodies = message.bodies('text/plain')
allBodies = '';
for body in plaintext_bodies:
allBodies = allBodies + body[1].decode()
if hasattr(message, "subject"):
subject, encoding = decode_header(message.subject)[0]
post.caption = unicode(subject)
post.author = message.sender
post.content = allBodies
post.images = img_links
post.videos = video_links
post.source = "email"
post.put()
示例6: publish
def publish(post_meta):
doc_id = Post.url_friendly_text(post_meta["title"])
# Open the database
couch = couchdb.Server()
db = couch["mrvoxel_blog"]
# Load the database settings
blog_settings = settings.loadSettings(db)
# Check to see if we have a valid category
if not post_meta["category"] in blog_settings["blog_categories"]:
raise ValueError("No such category: %s" % post_meta["category"])
print "checking for [%s]" % doc_id
# Load the post (if it exists in our database)
post = Post.load(db, doc_id)
# If it exists, warn the user
if post:
raw = raw_input("This will replace an existing post of the same title...\nContinue? (y/N)")
# if the existing post is published but we're trying to preview
if (post["published"] == False) and post_meta["published"]:
raise ValueError("Cannot yet preview posts that are already published")
if raw != "y":
print "Canceling publish."
return None
else:
for k, v in post_meta.iteritems():
if k not in ["published", "title"]:
print k
post[k] = v
print post
"""
post.markdown = mdtext
post.html = html
post.author = author
post.timestamp = timestamp
post.published = not preview
post.title = title
post.tags = tags
post.category = category
"""
post.store(db)
else:
post = Post.create(**post_meta)
print post["_id"]
post.store(db)
print post["_id"]
return post["_id"]
示例7: new_post
def new_post(self, title, content, date=datetime.datetime.utcnow()):
post = Post(blog_id=self._id,
title=title,
content=content,
author=self.author,
# formats the date string object into datetime
date=date)
post.save_to_mongo()
示例8: load_post
def load_post(self):
""" load post
"""
for post_source in glob.glob(self.post_path + self.post_pattern):
post = Post()
post.load_from_file(post_source)
# self.posts.append(post)
self.post_mapping[post.link] = post
示例9: post
def post(self):
user = users.get_current_user()
if user:
post = Post(parent = Post.post_db_key(), author = user, content = self.request.get("content"))
post.put()
self.redirect('/')
示例10: mod_post
def mod_post(args):
posts = Post.load()
if not args.title and not args.body:
print('Either title or body are required for post modificaion')
else:
p = Post(args.title or posts[args.postid]['title'],
args.body or posts[args.postid]['body'],
postid=args.postid)
p.save()
示例11: render_latest_posts
def render_latest_posts(self, limit):
accu = ''
for post_path in self.latest_posts(limit):
post = Post(post_path)
accu += post.render("short-post")
output = open(os.path.join(
self.__render_base_path, "latest_posts.rst"), "w", encoding='utf-8')
output.write(accu)
output.close()
示例12: render_latest_posts
def render_latest_posts(self, limit):
accu = ''
for post_path in self.latest_posts(limit):
post = Post(post_path)
accu += post.render('short-post')
output = open(os.path.join(
self.__render_base_path, 'latest_posts.rst'), 'w')
output.write(accu)
output.close()
示例13: get
def get(self):
post_id = self.request.get('post_id')
user_id = self.user.key().id()
if user_id and post_id and not LikePostRelation.check_like_status(user_id,post_id):
Post.updateLike(post_id)
like_post_relation = LikePostRelation.create_like_post_relation(user_id,post_id)
like_post_relation.put()
self.redirect('/blog/%s' % post_id)
示例14: get_post
def get_post(self, post_id):
post = self.loaded_posts.get(post_id, None)
if post is None:
path = u"{0}/{1}.md".format(self.working_dir, post_id)
if os.path.exists(path):
post = Post(post_id, working_dir=self.working_dir)
self.loaded_posts[post_id] = post
else:
post.refresh()
return post
示例15: post
def post(self):
user = users.get_current_user()
if not user or not users.is_current_user_admin():
self.redirect(users.create_login_url(self.request.uri))
return
post = Post()
post.title = self.request.POST['title']
post.put()
self.redirect('/admin/posts/edit/' + str(post.key.id()))