本文整理汇总了Python中models.Post.date方法的典型用法代码示例。如果您正苦于以下问题:Python Post.date方法的具体用法?Python Post.date怎么用?Python Post.date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.date方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_blog_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import date [as 别名]
def add_blog_post(request):
if request.method == "POST":
post = Post()
post.title = request.POST.get('title')
post.text = request.POST.get('text')
if not post.title or not post.text:
return HttpResponse("400 Bad Request You need to specify a title and message")
post.date = datetime.datetime.now()
post.save()
return json_response(request, 'Success')
else:
return HttpResponse("405 Method Not Allowed")
示例2: getPosts
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import date [as 别名]
def getPosts(blog):
if blog.url.endswith('persianblog.ir'):
url = "http://%s/rss.xml" % (blog.url)
else:
url = "http://%s/rss" % (blog.url)
print "going to parse: ", url
feed = feedparser.parse(url)
for entry in feed.entries:
if postExists(entry['link']):
continue
post = Post()
post.title = entry['title']
post.text = clean_html(entry['description'])
if hasattr(entry, 'published_parsed'):
post.date = datetime.fromtimestamp(mktime(entry['published_parsed']))
elif hasattr(entry, 'updated_parsed'):
post.date = datetime.fromtimestamp(mktime(entry['updated_parsed']))
else:
post.date = datetime.now()
post.url = entry['link']
post.blog = blog
post.save()
return feed
示例3: convert_to_entity
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import date [as 别名]
def convert_to_entity(json):
if json['status'] != "publish" or json['slug'] == 'placeholder':
return None
post = Post(key=get_key(json['slug']))
post.title = json['title']
post.content = json['content'].replace("\n", "")
date = json['modified']
post.time_added = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
if len(json['categories']) > 0:
category = json['categories'][0]
if category['parent'] != 8:
return None
key = categories.get_key(category['slug'])
post.category = key
else:
return None
date = json['date']
post.date = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
return post
示例4: parse_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import date [as 别名]
def parse_post(self, content, wall_owner):
from models import Post
from vkontakte_users.models import User
remote_id = content['id'][4:]
try:
instance = Post.objects.get(remote_id=remote_id)
except Post.DoesNotExist:
instance = Post(remote_id=remote_id)
post_text = content.find('div', {'class': 'wall_post_text'})
if post_text:
instance.text = post_text.text
# date
instance.date = self.parse_container_date(content)
# likes
instance.likes = self.parse_container_likes(content, 'post_like_count fl_l')
# comments
show_comments = content.find('div', {'class': 'wrh_text'})
if show_comments:
comments_words = show_comments.text.split(' ')
if len(comments_words) in [3,4]:
# Показать все 95 комментариев
# Показать 91 комментарий
instance.comments = int(comments_words[-2])
elif len(comments_words) == 6:
# Показать последние 100 комментариев из 170
instance.comments = int(comments_words[-1])
else:
raise VkontakteParseError("Error number of words in show all comments message: '%s'" % show_comments.text.encode('utf-8'))
else:
instance.comments = len(content.findAll('div', {'class': 'reply_text'}))
# author
owner_slug = content.find('a', {'class': 'author'})['href'][1:]
if wall_owner and wall_owner.screen_name == owner_slug:
instance.author = wall_owner
else:
# author is someone else,
# possible user, becouse the group can post only on it's own wall, where wall_owner is defined
avatar = content.find('a', {'class': 'post_image'}).find('img')['src']
name_parts = content.find('a', {'class': 'author'}).text.split(' ')
user = get_object_by_slug(owner_slug)
if user:
user.first_name = name_parts[0]
if len(name_parts) > 1:
user.last_name = name_parts[1]
user.photo = avatar
user.save()
instance.author = user
instance.fetched = datetime.now()
if wall_owner:
instance.wall_owner = wall_owner
#<td>
# <div class="published_by_title"><a class="published_by" href="/yullz">Yulya Tsareva</a> </div>
# <div class="published_by_date"><a class="published_by_date" href="/wall59124156_8301" onclick="return showWiki({w: 'wall59124156_8301'}, false, event);" >29 янв 2013 в 15:51</a></div>
#</td>
try:
slug = content.find('a', {'class': 'published_by'})['href'][1:]
post_link = content.find('a', {'class': 'published_by_date'})
instance.copy_owner = get_object_by_slug(slug)
instance.copy_post = Post.objects.get_or_create(remote_id=content.find('a', {'class': 'published_by_date'})['href'][5:], defaults={
'wall_owner': instance.copy_owner,
'date': self.parse_date(post_link.text)
})[0]
except:
pass
# <div class="published_comment wall_post_text">дядька молодец</div>
copy_text = content.find('div', {'class': 'published_comment wall_post_text'})
if copy_text:
instance.copy_text = copy_text.text
post_parsed.send(sender=Post, instance=instance, raw_html=str(content))
return instance