当前位置: 首页>>代码示例>>Python>>正文


Python News.objects方法代码示例

本文整理汇总了Python中models.News.objects方法的典型用法代码示例。如果您正苦于以下问题:Python News.objects方法的具体用法?Python News.objects怎么用?Python News.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.News的用法示例。


在下文中一共展示了News.objects方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getNewsList

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def getNewsList(request):
    # depend on the friends depart
    num = request.GET['num']
    allFriends = Account.objects(pk__in=request.user.friends).all()
    number = News.objects(author__in=allFriends).count()
    if int(num)*15>number:
        result=[]
        return HttpResponse(dumps(result))
    result = News.objects(author__in=allFriends)[int(num)*15:int(num)*15 + 15].order_by("-time").as_pymongo()
    result = list(result)
    for news in result:
        del(news['_types'])
        del(news['_cls'])
        news['picture'] = endpoint + "news/getPicture?id=" + str(news['_id'])
        news['voice'] = endpoint + "news/getVoice?id=" + str(news['_id'])
        uid = news['author']
        user = News.objects(author=uid).first().author
        gid = news['good']
        good = News.objects(good=gid).first().good
        news['good'] = endpoint + "goods/getGoods?id=" + str(good.pk)
        news['author'] = {"portrait": endpoint + "users/getPortrait?id=" + str(user.pk), "name": user.username}
        news['comments'] = endpoint + "news/getComments?id=" + str(news['_id'])
#        news['_id'] = endpoint + "news/getNewsDetail?id=" + str(news['_id'])
        del(news['_id'])
        news['time']=str(news['time'])
    result = dumps(result)
    return HttpResponse(result)
开发者ID:princenju,项目名称:ebayWithVoice,代码行数:29,代码来源:views.py

示例2: getNewsDetail

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def getNewsDetail(request):
    nid=request.GET['id']
    news=News.objects(pk=nid).first().to_mongo()
    del(news['_types'])
    del(news['_cls'])
    news['picture'] = endpoint + "news/getPicture?id=" + str(news['_id'])
    news['voice'] = endpoint + "news/getVoice?id=" + str(news['_id'])
    uid = news['author']
    user = News.objects(author=uid).first().author
    gid = news['good']
    good = News.objects(good=gid).first().good
    news['good'] = endpoint + "goods/getGoods?id=" + str(good.pk)
    news['author'] = {"portrait": endpoint + "users/getPortrait?id=" + str(user.pk), "name": user.username}
    news['comments'] = endpoint + "news/getComments?id=" + str(news['_id'])
#    news['_id'] = endpoint + "news/getNewsDetail?id=" + str(news['_id'])
    del(news['_id'])
    news['time']=str(news['time'])
    return HttpResponse(dumps(news))
开发者ID:princenju,项目名称:ebayWithVoice,代码行数:20,代码来源:views.py

示例3: getCommentVoice

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def getCommentVoice(request):
    vid=request.GET['vid']
    a=News.objects(comments__voice=ObjectId(str(vid))).first()
    comments=a.comments
    voice=None
    for comment in comments:
        mongo=comment.to_mongo()
        if str(mongo['voice'])==str(vid):
            voice=comment.voice
    return HttpResponse(voice.read(),mimetype="audio/mpeg")
开发者ID:princenju,项目名称:ebayWithVoice,代码行数:12,代码来源:views.py

示例4: post

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
 def post(self, request):
     try:
         api_news_ids = request.data
         top_news_id_list = []
         for news_id in api_news_ids:
             row = News.objects(news_id=news_id).first()
             if not row:
                 top_news_id_list.append(news_id)
         return Response({"data": top_news_id_list, "statusCode" : 200})
     except Exception, e:
         log.debug(str(e) + " IN TopNewsIdApi ")
         return Response({"data": "failure", "statusCode" : 404})
开发者ID:navneet03,项目名称:HackerNewsApi,代码行数:14,代码来源:views.py

示例5: getComments

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def getComments(request):
    nid=request.GET['id']
    news=News.objects(pk=nid).as_pymongo()
    comments=list(news)[0]["comments"]
    for comment in comments:
        del(comment["_types"])
        del(comment["_cls"])
        uid=comment["author"]
        user = Account.objects(pk=uid.id).first()
        if comment["voice"]!=None:
            comment["voice"]=endpoint + "news/getCommentVoice?vid="+str(comment["voice"])
        else:
            comment["voice"]=""
        comment["username"]=user.username
        comment["portrait"]=endpoint+"users/getPortrait?id="+str(user.pk)
        del(comment["author"])
    return HttpResponse(dumps(comments))
开发者ID:princenju,项目名称:ebayWithVoice,代码行数:19,代码来源:views.py

示例6: addComment

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def addComment(request):
    result=urlparse.urlparse(request.POST['comment_url'])
    params=urlparse.parse_qs(result.query,True)
    nid=params['id']
    comment = Comment()
    comment.content =""
    if request.POST.has_key("content"):
        content = request.POST['content']
        comment.content = content
    if request.FILES.has_key("voice"):
        voice =open(request.FILES['voice'].temporary_file_path(), "rb")  # change to data from request
        comment.voice = voice
    comment.author = request.user
    news = News.objects(pk=nid[0]).first()
    news.comments = news.comments + [comment]
    news.save()
    return HttpResponse("success")
开发者ID:princenju,项目名称:ebayWithVoice,代码行数:19,代码来源:views.py

示例7: post

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
 def post(self, request):
     try:
         top_news_ids = request.data
         top_news_ids = json.dumps(top_news_ids)
         top_news_ids = ast.literal_eval(top_news_ids)
         top_news_ids = top_news_ids.keys()[0]
         top_news_ids = ast.literal_eval(top_news_ids)
         top_new_news_id_list = []
         for news_id in top_news_ids:
             news_id = long(news_id)
             a = News.objects(news_id=news_id).first()
             # News.objects(news_id=news_id).delete()
             if not a:
                 top_new_news_id_list.append(news_id)
         return Response({"new_news_id": top_new_news_id_list})
     except Exception, e:
         log.debug(str(e) + " IN TopNewsIdApi ")
         return Response({"status": "failure"})
开发者ID:avinashmail,项目名称:HackerNews,代码行数:20,代码来源:views.py

示例8: connect

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
import time

from mongoengine import connect
connect('newsclient')

from models import News

#for news in News.objects(facebook_count__gte=800).limit(1000):
for news in News.objects(hatebu_count__exists=0).limit(1000):
  if "rssad" in news.url:
    continue

  if news.twitter_count is None:
    news.get_twitter_count()
  if news.facebook_count is None:
    news.get_facebook_count()
  if news.hatebu_count is None:
    news.get_hatebu_count()

  if news.hatebu_count > 100 or\
      news.facebook_count > 800 or\
      news.twitter_count > 1200:
    print "tw", news.twitter_count
    print "fb", news.facebook_count
    print "hatebu", news.hatebu_count
    print news.og_title
    print news.url
  news.save()
  time.sleep(1)
开发者ID:yuiseki,项目名称:news_sandbox,代码行数:31,代码来源:counter.py

示例9: getVoice

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def getVoice(request):
    nid = request.GET['id']
    result = News.objects(pk=nid).first()
    voice = result.voice.read()
    return HttpResponse(voice, mimetype="audio/mpeg")
开发者ID:princenju,项目名称:ebayWithVoice,代码行数:7,代码来源:views.py

示例10: getPicture

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def getPicture(request):
    nid = request.GET['id']
    result = News.objects(pk=nid).first()
    image = result.picture.read()
    return HttpResponse(image, mimetype="image/jpeg")
开发者ID:princenju,项目名称:ebayWithVoice,代码行数:7,代码来源:views.py

示例11: deleteNews

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
def deleteNews(request):
    News.objects(author=request.user).delete()
    return HttpResponse("delete all")
开发者ID:princenju,项目名称:ebayWithVoice,代码行数:5,代码来源:views.py

示例12: connect

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import objects [as 别名]
import time
from mongoengine import connect
from mongoengine import Q
from models import News
connect('newsclient')

queryset = News.objects(\
    Q(generated_summary__exists=0) &\
    Q(url__not__contains="rssad") )#  &\
    #Q(url__not__contains="nhk") ).limit(50)

for news in queryset:
  print ">>>>>>>>>>-------------------"
  print news.url
  print news.og_title
  news.extract_content_()
  news.generate_summary()
  print news.generated_summary
  news.save()
  #time.sleep(5)
  print "-------------------<<<<<<<<<<\n"
开发者ID:yuiseki,项目名称:news_sandbox,代码行数:23,代码来源:generate_summary.py


注:本文中的models.News.objects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。