本文整理汇总了Python中tag.Tag.findByTitle方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.findByTitle方法的具体用法?Python Tag.findByTitle怎么用?Python Tag.findByTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tag.Tag
的用法示例。
在下文中一共展示了Tag.findByTitle方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
# 需要导入模块: from tag import Tag [as 别名]
# 或者: from tag.Tag import findByTitle [as 别名]
def index(request):
freqTopicSets = ''
query = ''
freqTopics = ''
time2 = datetime.datetime.now()
time1 = time2 - timedelta(days=1)
print('timing: before freqTopics')
print(datetime.datetime.now())
freqTopics = Analysis.getFreqTopics(time1, time2, minFreq=0, k=params.maxFreqTopics)
time22 = time1
time11 = time22 - timedelta(days=2*params.days) # to be used to find the old frequencies of current hot topics
freqTopics = Analysis.getTopicsFrequencyChanges(freqTopics, time11, time22) # find trendings for freq topic sets
#pdb.set_trace() how to do debugging
#print('timing: after freqTopics')
#print(datetime.datetime.now())
#if request.method == 'GET' : # If form is submitted
form = searchForm(request.GET)
tag = ''
linkSets = []
topicSet_linkSets = []
if form.is_valid():
if(request.GET.has_key('input')):
print('timing: before getFreqTopicSets')
print(datetime.datetime.now())
freqTopicSets = Analysis.getFreqTopicSets(request.GET['input'], time1, time2)
print('timing: after getFreqTopicSets')
print(datetime.datetime.now())
for topicSet in freqTopicSets:
tag_ids = []
links = []
#cuz example topicSet for a query like Microsoft = (['Blog', 'Android'], 4) so make into ['Blog', 'Android', 'Microsoft']
topics = topicSet[0]
topics.append(str(request.GET['input']))
for topic in topics:
tag = Tag.findByTitle(topic) #findByTitle returns multiple rows representing multiple tags, so the last [0][0] means get the first attribute (ie id) or the first tag in rows
#pdb.set_trace()
tag_id = tag[0][0]
tag_id = str(tag_id).strip('L') #seems like we get id's like '3167L' strip the L
tag_ids.append(tag_id)
#print("in views.py:")
print(topicSet)
#pdb.set_trace()
#print('====')
#print(datetime.datetime.now())
feeditems = feeditem.Feeditem.findByTags(tag_ids, time1, time2)
#print(datetime.datetime.now())
for item in feeditems:
print item[1]
t1 = unicode(unicode(item[1],'utf-8', errors='ignore')) # to ignore non utf-8 chars
t2 = unicode(item[3])
links.append((t1,t2))
linkSets.append(copy.copy(links))
topicSet_linkSets = zip(freqTopicSets, linkSets)
else:
form = searchForm()
if(request.GET.has_key('input')):
query = request.GET['input']
else:
qeury = None
return render_to_response('ui/index.html', {'form' : form, 'freqTopicSets':freqTopicSets, 'query':
query, 'freqTopics':freqTopics, 'linkSets':linkSets, 'topicSet_linkSets':topicSet_linkSets[::-1] })