本文整理汇总了Python中models.News.id方法的典型用法代码示例。如果您正苦于以下问题:Python News.id方法的具体用法?Python News.id怎么用?Python News.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.News
的用法示例。
在下文中一共展示了News.id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: inner_update
# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import id [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
示例2: get_news_search_queryset
# 需要导入模块: from models import News [as 别名]
# 或者: from models.News import id [as 别名]
def get_news_search_queryset(city, q):
try:
sphinx.SetFilter('city', [int(city)], exclude=0)
search_result = sphinx.Query(q, 'article', '')
sphinx.ResetFilters()
items = []
for match in search_result['matches']:
news = News()
news.id = match['id']
for key, value in match['attrs'].iteritems():
setattr(news, key, value)
items.append(news)
except:
error = sphinx.GetLastError()
raise Exception('search', error)
#queryset = News.objects.filter(is_displayed=True, city=city, title__icontains=q).order_by('-date_added')
if items and len(items) > 0:
photos = NewsPhoto.objects.filter(display_order=0, subnews_id__isnull=True)
photos_dict = {}
for p in photos:
photos_dict[p.news_id] = p
for item in items:
item.photo = photos_dict[item.id] if item.id in photos_dict.keys() else None
return items
else:
return []