本文整理汇总了Python中utils.Utils.genDescHtml方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.genDescHtml方法的具体用法?Python Utils.genDescHtml怎么用?Python Utils.genDescHtml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.Utils
的用法示例。
在下文中一共展示了Utils.genDescHtml方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Bookmark
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import genDescHtml [as 别名]
#.........这里部分代码省略.........
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 = ''
page_num = 6
page = 'http://www.xmarks.com/topic/' + key
nextpage = ''
page_count = 0
for i in range(0, page_num):
page_count += 1
if nextpage != '':
page = nextpage.replace('2', str(page_count))
print 'request ' + page
r = requests.get(page, cookies=cookies)
if r.status_code != 200:
break
soup = BeautifulSoup(r.text)
#print r.text
for div in soup.find_all('div', class_='content'):
count += 1
title = self.colorkeyword(div.a.text, key)
html += '<li><span>' + str(count) + '.</span><p>' + self.utils.enhancedLink(div.a['href'], title, module='xmarks', library=orginFilename) + self.utils.getIconHtml(div.a['href'])
示例2: Social
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import genDescHtml [as 别名]
class Social(BaseExtension):
def __init__(self):
BaseExtension.__init__(self)
self.utils = Utils()
self.tag = Tag()
self.form_dict = None
def excute(self, form_dict):
self.form_dict = form_dict
rID = form_dict['rID'].strip()
rTitle = form_dict['rTitle'].strip()
originFileName = form_dict['originFileName'].strip()
url = form_dict['url'].strip()
#r = requests.get(url, proxies=Config.proxies3)
r = requests.get(url)
soup = BeautifulSoup(r.text)
links = soup.find_all("a")
socialDict = {}
linkKey = self.getLinkKey(url)
desc = ''
for link in links:
if link.has_attr(linkKey):
#print link
key = self.socialKey(link[linkKey])
if key != '':
linkUrl = link[linkKey]
if socialDict.has_key(key) and socialDict[key] != linkUrl:
desc += self.genDesc(key, linkUrl) + ' '
else:
socialDict[key] = linkUrl
print socialDict
html = ''
if len(socialDict) > 0:
for k, v in socialDict.items():
desc += self.genDesc(k, v) + ' '
print ''
print desc.strip().replace(':', '(').replace(' ', ')+').strip() + ')'
print desc.strip().replace(':', '(').replace(' ', '), ').strip() + ')'
print ''
splitChar = '<br>'
if self.form_dict.has_key('client') and self.form_dict['client'] == 'plugin':
splitChar = ' '
descHtml = self.utils.genDescHtml(desc, Config.course_name_len, self.tag.tag_list, iconKeyword=True, fontScala=1, splitChar=splitChar)
html = '<br>' + descHtml
script = self.utils.getBatchOpenScript(socialDict.keys(), socialDict.values(), 'social', onePage=False)
html += '<a target="_blank" href="javascript:void(0);" onclick="' + script + '">#all</a>'
html += '<br>'
return html
def genDesc(self, k, v):
v = self.preUrl(v)
if v.endswith('/'):
v = v[0 : len(v) - 1]
socialUrl = self.preUrl(self.tag.tag_list_account[k])
#print v + ' ' + socialUrl
#print v
print k + v.replace(socialUrl, '')
return k +v.replace(socialUrl, '')
def getLinkKey(self, url):
#if url.find('google') != -1:
# return 'data-href'
return 'href'
def socialKey(self, url):
result = ''
preurl = self.preUrl(url)
if preurl.find('/') != -1:
preurl = preurl[0 : preurl.find('/')]
for key in self.tag.tag_list_account.keys():
if preurl.find(key.replace(':', '')) != -1:
result = key
else:
#.........这里部分代码省略.........
示例3: History
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import genDescHtml [as 别名]
#.........这里部分代码省略.........
titleList = []
urlList = []
htmlList = []
descHtmlList = []
aidList = []
refreshIDList = []
count = 0
for item in rList:
title = item.get_title().strip().replace('%20', ' ')
titleList.append(title)
#print titleList
urlList.append(item.get_url().strip())
appendFrontHtml = ''
if title.lower() != Config.history_quick_access_name.lower():
appendFrontHtml = self.utils.genQuickAcessButton(item, 'history', iconType='remark')
else:
appendFrontHtml = self.utils.genQuickAcessButton(item, 'history')
if title.lower() != Config.history_quick_access_name.lower():
htmlList.append(appendFrontHtml + self.getDeleteButton(divID, historyFile, item.get_url().strip()))
else:
#html = self.utils.getIconHtml('', 'quickaccess')
html += appendFrontHtml + self.genQuickAccessSyncButton(rID, quickAccessHistoryFile, divID, objID) + ' '
htmlList.append(html)
count += 1
refreshID = self.getRefreshID(self.divID, title)
aid = self.getAID(self.divID, count)
aidList.append(aid)
refreshIDList.append(refreshID)
descHtmlList.append(self.utils.genDescHtml(item.get_describe().strip(), Config.course_name_len, self.tag.tag_list, iconKeyword=True, fontScala=1, aid=aid, refreshID=refreshID, module='history', unfoldSearchin=False))
#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)
'''
示例4: Content
# 需要导入模块: from utils import Utils [as 别名]
# 或者: from utils.Utils import genDescHtml [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