Commit 938f6751 authored by Kevin Deldycke's avatar Kevin Deldycke

Little script to get content summary of a webpage (should be renamed WebPage_getContentSummary).

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@8104 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f9f47c0f
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.PythonScripts.PythonScript</string>
<string>PythonScript</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
no_summary_message = "News vide !"\n
\n
if news_full_text in [None, \'\']:\n
return no_summary_message\n
\n
# XXX ! Big Security issue here !!!\n
# Must be replaced by http://www.zope.org/Members/itamar/striphtml ? \n
\n
# Other Alternative:\n
# from stripogram import html2text\n
# return html2text(news_full_text)\n
\n
def StripTags(text):\n
finished = 0\n
while not finished:\n
finished = 1\n
# check if there is an open tag left\n
start = text.find("<")\n
if start >= 0:\n
# if there is, check if the tag gets closed\n
stop = text[start:].find(">")\n
if stop >= 0:\n
# if it does, strip it, and continue loop\n
text = text[:start] + text[start+stop+1:]\n
finished = 0\n
return text\n
\n
# End of bad HTML tag stripping\n
\n
word_list = StripTags(news_full_text).split(\' \')\n
\n
# Get the first 30 words of the news\n
word_count = 30\n
summary = \'\'\n
for word in word_list:\n
if len(word) > 0:\n
summary += word + \' \'\n
word_count -= 1\n
if word_count == 0:\n
break\n
\n
return summary\n
]]></string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_filepath</string> </key>
<value> <string>Script (Python):/nexedi/portal_skins/erp5_web/WebSite_getNewsItemSummary</string> </value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>news_full_text=None</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>news_full_text</string>
<string>no_summary_message</string>
<string>None</string>
<string>StripTags</string>
<string>_getattr_</string>
<string>word_list</string>
<string>word_count</string>
<string>summary</string>
<string>_getiter_</string>
<string>word</string>
<string>len</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<tuple>
<none/>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WebSite_getNewsItemSummary</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment