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


Python News.title方法代码示例

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


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

示例1: inner_update

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import title [as 别名]
def inner_update(para_date):
    if para_date is None:
        url = 'http://news.at.zhihu.com/api/1.2/news/latest'
    else:
        time1 = datetime.strptime(para_date, '%Y%m%d')
        para_date = get_tomorrow(time1).strftime('%Y%m%d')
        url = 'http://news.at.zhihu.com/api/1.2/news/before/'+para_date
    header = {'User-Agent':
              'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4'}
    req = urllib2.Request(url, headers=header)
    webcode = urllib2.urlopen(req).read()

    data_dict = json.loads(webcode)  # 所有数据的dict
    news_count = len(data_dict['news'])  # 子dick news
    if news_count < 1:
        return False
    the_date = data_dict['date']

    data_dict['news'].reverse()  # 反转List

    for i in range(0, news_count):
        new_obj = News()

        a_new = data_dict['news'][i]
        new_obj.id = a_new['id']
        new_obj.title = a_new['title']
        new_obj.share_url = a_new['share_url']
        new_obj.api_url = a_new['url']
        new_obj.image_url = a_new['image']
        new_obj.image_source = a_new['image_source']
        new_obj.seq = i
        new_obj.date = the_date

        new_obj.save()
    return True
开发者ID:liyuntao,项目名称:zhihu_daily,代码行数:37,代码来源:views.py

示例2: add_news

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import title [as 别名]
def add_news(req):
    check = News.objects.filter(link=req.POST['link'])
    mnews = ""
    if check.count() != 0:
        # record already exist
        if check[0].time > int(req.POST['time']):
            return HttpResponse(json.dumps({'status':'OK'},indent=4),content_type='application/json')
        mnews = check[0]
    else:
        mnews = News()
    mnews.title = req.POST['title']
    mnews.content = req.POST['content']
    mnews.link = req.POST['link']
    mnews.time = int(req.POST['time'])
    mnews.save()
    keywords = json.loads(req.POST['keywords'])
    refers = json.loads(req.POST['refers'])
    for word in keywords:
        mkeywords = Keywords()
        mkeywords.news = mnews
        mkeywords.words = word
        mkeywords.save()
    for refer in refers:
        mrefer = Refers()
        mrefer.news = mnews
        mrefer.refer = refer
        mrefer.save()
    return HttpResponse(json.dumps({'status':'OK'}),content_type='application/json')
开发者ID:randoms,项目名称:prophet,代码行数:30,代码来源:views.py

示例3: post

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import title [as 别名]
 def post(self):
     news = News()
     news.title = self.request.get("title")
     news.slug_title = self.request.get("slug_title")
     news.content = self.request.get("content")
     news.when_published = datetime.utcnow()
     news.put()
     self.response.out.write(news.to_json("title", "is_deleted", "is_active", "is_starred"))
开发者ID:aswadrangnekar,项目名称:tiss-secure,代码行数:10,代码来源:api.py

示例4: add_news

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import title [as 别名]
def add_news(request):
    imgroot = '/var/pj/gk/st/news/'
    imgroot54x54 = '/var/pj/gk/st/news/54x54/'
    if request.method == "POST":
        title = request.POST['news_name']
        tags = request.POST['news_tags']
        active = request.POST['news_status']
        category = request.POST['news_category']
        sweight = request.POST['news_priority']
        date = request.POST['news_date']
        text = request.POST['news_content']
        n = News()
        if 'news_autor' in request.POST:
            n.autor = request.POST['news_autor']
        if 'news_photo_autor' in request.POST:
            n.photo_title = request.POST['news_photo_autor']
        if 'news_origin' in request.POST:
            n.origin = request.POST['news_origin']
        if 'news_city' in request.POST:
            n.city = request.POST['news_city']
        if 'news_media' in request.POST:
            n.media = request.POST['news_media']
        user = User.objects.get(username=request.user)
        n.owner = user
        n.title = title
        if active == 'on':
            active = True
        else:
            active = False
        n.active = active
        n.text = text
        n.sweight = sweight
        n.date = date
        n.save()
        tagsl = tags.split(',')
        tagsitems = []
        for item in tagsl:
            if len(item.strip()):
                tagsitems.append(Tag.objects.get_or_create(name=item.strip())[0].id)
        n.tags = tagsitems
        categoryl = category.split(',')
        categoryitems = []
        for item in categoryl:
            if len(item.strip()):
                categoryitems.append(item)
        n.category = categoryitems
        tmpfile = handle_uploaded_file(request.FILES['news_logo'], str(n.id) + request.FILES['news_logo'].name[-4:])
        img = Image.open('/tmp/' + tmpfile)
        img.save(imgroot + str(n.id) + '.png', 'PNG')
        img.thumbnail([54, 54], Image.ANTIALIAS)
        img.save(imgroot54x54 + str(n.id) + '.png', 'PNG')
        request.session['alert'] = 'Новость успешно добавлена'
        return redirect('/news/admin/')
开发者ID:TorinAsakura,项目名称:gk,代码行数:55,代码来源:views.py

示例5: admin_news_uploads

# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import title [as 别名]
def admin_news_uploads():
	form = UploadNewsForm()
	if form.validate_on_submit():
		news = News()
		db.session.add(news)
		db.session.commit()
		news.title = form.title.data
		news.content = form.content.data
		news.author = current_user.username

		file_name = secure_filename(form.image.data.filename)
		extension = file_name.split('.')[-1]
		file_name = '.'.join([str(news.id), extension])
		path = upload_s3(file_name, form.image.data, app.config['S3_NEWS_IMAGE_DIR'])
		news.image = path
		db.session.commit()
	return redirect(url_for('news_and_resources'))
开发者ID:berc-web,项目名称:berc_web,代码行数:19,代码来源:__init__.py


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