本文整理汇总了Python中utils.Utils.formatTitle方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.formatTitle方法的具体用法?Python Utils.formatTitle怎么用?Python Utils.formatTitle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.Utils
的用法示例。
在下文中一共展示了Utils.formatTitle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Rss
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import formatTitle [as 别名]
class Rss(BaseExtension):
def __init__(self):
BaseExtension.__init__(self)
self.utils = Utils()
def excute(self, form_dict):
fileName = form_dict['fileName'].encode('utf8')
rID = form_dict['rID'].encode('utf8')
url = form_dict['url']
return self.genHtml(url, form_dict['divID'].encode('utf8'), rID)
def check(self, form_dict):
fileName = form_dict['fileName'].encode('utf8')
rID = form_dict['rID'].encode('utf8')
return fileName.find('rss/') != -1 and rID.startswith('loop') == False
def genHtml(self, feed_url, ref_divID, rID):
f = feedparser.parse( feed_url )
print "Feed Title %s" % f.feed.title
count = 0
html = ''
html += '<div class="ref"><ol>'
for entry in f.entries:
print "Title: %s" % entry.title
print "link: %s" % entry.link
count += 1
html += '<li><span>' + str(count) + '.</span>'
html += '<p><a target="_blank" href="' + entry.link + '"> '+ self.utils.formatTitle(entry.title, 60) + '</a>'
ref_divID += '-' + str(count)
linkID = 'a-' + ref_divID[ref_divID.find('-') + 1 :]
appendID = str(count)
script = self.utils.genMoreEnginScript(linkID, ref_divID, "loop-" + rID.replace(' ', '-') + '-' + str(appendID), entry.title, entry.link, '-')
html += self.utils.genMoreEnginHtml(linkID, script.replace("'", '"'), '...', ref_divID, '', False);
html += '</p></li>'
html += '</ol></div>'
return html
示例2: Bookmark
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import formatTitle [as 别名]
#.........这里部分代码省略.........
if len(notList) > 0 and self.do_match_item(jobj, notList):
return False, ''
return self.do_match_item(jobj, rTitleList)
def do_match_item(self, jobj, items):
for rTitle in items:
if rTitle.strip() == '':
continue
if self.containIgoncase(jobj['title'].strip(), rTitle.strip()):
#print jobj['title'].strip() + ' ' + rTitle.strip()
return True, rTitle.strip()
if jobj.has_key('url') and len(rTitle) > 8:
if self.containIgoncase(jobj['url'].strip(), rTitle.replace(' ', '').strip()):
return True, ''
if self.containIgoncase(jobj['url'].strip(), rTitle.replace(' ', '%20').strip()):
return True, ''
if self.containIgoncase(jobj['url'].strip(), rTitle.strip().replace(' ', '-')):
return True, ''
if self.containIgoncase(jobj['title'].strip(), rTitle.strip().replace(' ', '-')):
return True, rTitle.strip().replace(' ', '-')
return False, ''
def gen_item(self, rID, ref_divID, count, jobj, moreOption, orginFilename, keywords=[], higtLightText=''):
html = ''
html += '<li><span>' + str(count) + '.</span>'
url = ''
if jobj.has_key('url'):
url = jobj['url']
showText = self.utils.formatTitle(jobj['title'], Config.smart_link_br_len, keywords)
if higtLightText != '':
showText = self.utils.doHighLight(showText, higtLightText, appendValue=False)
if url != '':
html += '<p>' + self.utils.enhancedLink(url, self.utils.formatTitle(jobj['title'], Config.smart_link_br_len, keywords), module='bookmark', library=orginFilename, rid=rID, aid=rID, showText=showText) + self.utils.getIconHtml(url)
else:
html += '<p>' + showText + self.utils.getIconHtml(".dir", radius=False) #' > '
#if self.existChild(str(jobj['id'])):
# html += ' > '
if moreOption:
ref_divID += '-' + str(count)
linkID = 'a-' + ref_divID[ref_divID.find('-') + 1 :]
appendID = str(count)
script = self.utils.genMoreEnginScript(linkID, ref_divID, "loop-b-" + rID.replace(' ', '-') + '-' + str(appendID) + '-' + str(jobj['id']), jobj['title'], url, '-', hidenEnginSection=Config.bookmark_hiden_engin_section)
descHtml = ''
if url != '':
descHtml = self.utils.genDescHtml('url:' + url, Config.course_name_len, self.tag.tag_list)
#print 'descHtml:' + descHtml
html += self.utils.genMoreEnginHtml(linkID, script.replace("'", '"'), '...', ref_divID, '', False, descHtml=descHtml);
html += '</p></li>'
return html
def genWebsiteHtml(self, key, orginFilename):
html = '<ol>'
count = 0
cookies = dict(unsafe='True')
page = ''
示例3: History
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import formatTitle [as 别名]
#.........这里部分代码省略.........
#splitNumber = len(rList) / 3
splitNumber = 0#len(rList)
return self.utils.toListHtml(titleList, urlList, htmlList, descHtmlList=descHtmlList, splitNumber=splitNumber, moreHtml=True, aidList=aidList, refreshIDList=refreshIDList, orginFilename=form_dict['originFileName'])
else:
html += '<div class="ref"><ol>'
for item in rList:
title = item.get_title().strip().replace('%20', ' ')
count += 1
jobj_record = {}
jobj_record['id'] = rID + '-' + str(count)
jobj_record['title'] = title
jobj_record['url'] = item.get_url().strip()
jobj_record['count'] = self.getClickCount(item)
jobj_record['desc'] = item.get_describe()
jobj_record['parentDesc'] = parentDesc
#print jobj_record['desc']
appendHtml = ''
appendFrontHtml = ''
if title.lower() != Config.history_quick_access_name.lower():
appendFrontHtml = self.utils.genQuickAcessButton(item, 'history', iconType='remark')
appendHtml += self.getDeleteButton(divID, historyFile, item.get_url().strip()) + ' '
else:
#appendHtml = self.utils.getIconHtml('', 'quickaccess')
appendFrontHtml = self.utils.genQuickAcessButton(item, 'history')
appendHtml += self.genQuickAccessSyncButton(rID, quickAccessHistoryFile, divID, objID) + ' '
#print jobj_record
html += self.gen_item(rID, divID, count, jobj_record, Config.more_button_for_history_module, form_dict['fileName'], form_dict['originFileName'], appendFrontHtml='', appendAfterHtml=appendFrontHtml+appendHtml)
'''
html += '<li><span>' + str(count) + '.</span>'
html += '<p>' + self.utils.enhancedLink(item.get_url().strip(), self.utils.formatTitle(title, Config.smart_link_br_len, []), module='history', library=form_dict['originFileName'], rid=rID) + self.utils.getIconHtml(item.get_url().strip())
'''
html += "</ol></div>"
return html
else:
self.updateHistory()
if self.needBR():
html += '<br>'
html += '<div class="ref"><ol>'
count = 0
item_dict = {}
for jobj in self.jobj_list:
if self.match_item(jobj, [rTitle]) or self.match_item(jobj, alias):
if item_dict.has_key(jobj['title'].strip()):
continue
item_dict[jobj['title'].strip()] = ''
count += 1
html += self.gen_item(rID, divID, count, jobj, Config.more_button_for_history_module, form_dict['fileName'], form_dict['originFileName'])
html += "</ol></div>"
if count == 0:
html = ''
return html
def gen_item(self, rID, ref_divID, count, jobj, moreOption, fileName, orginFilename, keywords=[], appendFrontHtml='', appendAfterHtml='', parentDesc=''):
html = ''
html += '<li><span>' + str(count) + '.</span>'
url = ''
示例4: Reference
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import formatTitle [as 别名]
#.........这里部分代码省略.........
link = a['href']
print a['href']
if self.passItem(a.text.strip(), link):
continue
title = a.text.strip().encode('utf-8')
if title == '':
title = link.replace('http://', '').replace('www.', '')
link_dict[link] = link
link = self.utils.fixUrl(url, link)
text = title
if url.find('youtube') != -1 and link.find('watch') != -1:
link = 'https://www.youtube.com' + link[link.rfind('/watch') :]
if url.find('playlist') == -1:
if a.text.find('Duration') != -1:
text = self.formatYoutubeLink(a, True).replace(' ', '%20')
title = self.formatYoutubeLink(a, False)
else:
text = self.utils.removeDoubleSpace(a.text.strip()).replace(' ', '%20')
if title.startswith('/watch'):
continue
elif url.endswith('playlist') == False:
if count == 0:
return self.getAllLinks(link, ref_divID, rID)
count += 1
print str(count) + ' ' + title + ' ' + link
ref_divID += '-' + str(count)
linkID = 'a-' + ref_divID[ref_divID.find('-') + 1 :]
appendID = str(count)
script = self.utils.genMoreEnginScript(linkID, ref_divID, "loop-" + rID.replace(' ', '-') + '-' + str(appendID), text, link, '-', hidenEnginSection=Config.reference_hiden_engin_section)
#if a.img != None and a.img['src'].endswith('gif') == False:
# html += '<img width="48" height="48" src="' + a.img['src'] + '">'
html += '<li><span>' + str(count) + '.</span>'
if title.find('- Duration') != -1:
html += '<p>' + self.utils.enhancedLink(link, self.utils.formatTitle(title[0 : title.find('- Duration')], Config.reference_smart_link_br_len), module='reference') + title[title.find('- Duration') :]
records.append(self.toRecord('reference-' + str(count), title[0 : title.find('- Duration')], link))
else:
html += '<p>' + self.utils.enhancedLink(link, self.utils.formatTitle(title, Config.reference_smart_link_br_len), module='reference')
records.append(self.toRecord('reference-' + str(count), title, link))
if script != "":
html += self.utils.genMoreEnginHtml(linkID, script.replace("'", '"'), '...', ref_divID, '', False);
html += '</p></li>'
html += '</ol></div>'
if count == 0:
html = ''
if Config.reference_output_data_to_new_tab:
return self.utils.output2Disk(records, 'reference', self.form_dict['rTitle'], Config.reference_output_data_format)
else:
return html
def toRecord(self, rid, title, url):
return Record(rid + ' | ' + title.replace('\n', '') + ' | ' + url + ' | ')
def isYoutubeRssUrl(self, url):
return (url.find('user') != -1 or url.find('channel') != -1) and (url.find('playlists') != -1 or url.find('videos') != -1) and url.find('watch') == -1 and url.find('youtube') != -1
def youtubeRssHtml(self, url, rid, divid):
if url.find('playlist') != -1:
return self.genRssHtml(self.helper.getPlaylists(url), rid, divid)
elif url.find('video') != -1:
videos = self.helper.getVideos(url)
return self.genRssHtml(videos, rid, divid)
return ''
def genRssHtml(self, data, key, ref_divID):
示例5: Content
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import formatTitle [as 别名]
#.........这里部分代码省略.........
if contentref != None:
return contentref.strip()
return ''
def write(self, html):
f = open('temp/test.html', 'w')
for line in html:
f.write(line)
#print 'write ' + html + ' to file'
f.close
def genContentHtml(self, key, content_divID, defaultLinks, library):
return self.genMetadataHtml(key, content_divID, defaultLinks, library)
def genMetadataHtml(self, key, content_divID, defaultLinks, library):
html = '<div class="ref"><ol>'
if self.form_dict['column'] == '3' and int(self.form_dict['extension_count']) > 10:
html = '<div class="ref"><br><ol>'
count = 0
#print 'key:' + key
#print self.datafile_content
if self.datafile_content.has_key(key):
self.record_content = self.datafile_content
elif self.optional_content.has_key(key):
self.record_content = self.optional_content
if self.record_content.has_key(key):
#print key
for r in self.record_content[key]:
count += 1
format_index = ''
pRecord = None
pid = r.get_parentid().strip()
if self.record_content.has_key(pid) and key.find('-') != -1:
pRecord = self.record_content[pid]
if content_divID.find(self.data_type) == content_divID.rfind(self.data_type):
format_index = str(count)
else:
format_index = pid[pid.rfind('-') + 1 :] + '.' + str(count)
elif r.get_id().find('-') != -1:
format_index = r.get_id()[r.get_id().rfind('-') + 1 : ].strip()
while format_index.find('-') != -1:
format_index = format_index[format_index.find('-') + 1 :]
html += '<li><span>' + format_index + '</span>'
if len(format_index) > 5:
html += '</li><br/><li>'
content_divID += '-' + str(count)
linkID = 'a-' + content_divID[content_divID.find('-') + 1 :]
title = r.get_title().strip().replace(' ', '%20')
desc = r.get_describe().strip()
script = self.utils.genMoreEnginScript(linkID, content_divID, r.get_id().strip(), self.utils.clearHtmlTag(title), r.get_url().strip(), '-', hidenEnginSection=Config.content_hiden_engin_section)
descHtml = ''
if desc != '':
descHtml = self.utils.genDescHtml(desc, Config.course_name_len, self.tag.tag_list, iconKeyword=True, fontScala=1, module='history')
moreHtml = self.utils.genMoreEnginHtml(linkID, script.replace("'", '"'), '...', content_divID, '', False, descHtml=descHtml);
if self.record_content.has_key(r.get_id().strip()) or r.get_url().strip() == '':
if r.get_url().strip() != '':
html += '<p>' + self.genMetadataLink(r.get_title().strip(), r.get_url().strip())
else:
html += '<p>' + self.utils.toSmartLink(r.get_title().strip(), 45, module='content', rid=self.form_dict['rID'], library=library)
#html += self.utils.getDefaultEnginHtml(title, defaultLinks)
if moreHtml != "":
html += moreHtml
html += '</p>'
elif r.get_url().strip() != '':
html += '<p>' + self.genMetadataLink(r.get_title().strip(), r.get_url().strip()) + moreHtml + '</p>'
html += '</li>'
else:
return ''
html += "</ol></div>"
return html
def genMetadataLink(self, title, url):
if url.find('[') != -1:
ft = url.replace('[', '').replace(']', '').strip()
r = self.utils.getRecord(ft, '','', False, False)
key = r.get_path()[r.get_path().find(default_subject) + len(default_subject) + 1 :]
url = 'http://' + Config.ip_adress + '?db=' + default_subject + '/&key=' + key + '&filter=' + ft + '&desc=true'
return self.genMetadataLinkEx(title, url)
def genMetadataLinkEx(self, title, url):
if title.find('<a>') != -1:
title = title.replace('<a>', '<a target="_blank" href="' + url + '">')
else:
title = self.utils.enhancedLink(url, self.utils.formatTitle(title, 45), module='content', rid=self.form_dict['rID'], library=self.form_dict['originFileName'])
return title