plugins/rss_plugin.py
changeset 39 2123977057c5
parent 38 a81dc352e96e
child 40 0d917adf0daf
equal deleted inserted replaced
38:a81dc352e96e 39:2123977057c5
    15 initialize_file(RSS_CACHE_FILE, "{'channels': {}}")
    15 initialize_file(RSS_CACHE_FILE, "{'channels': {}}")
    16 
    16 
    17 ################################################################################
    17 ################################################################################
    18 
    18 
    19 import re
    19 import re
       
    20 
       
    21 html_table = [
       
    22 	('<p>'  , '' ),
       
    23 	('</p>' , '' ),
       
    24 	('<p />', '' ),
       
    25 	('<p/>' , '' ),
       
    26 	('>'       , '>'),
       
    27 	('>'       , '>'),
       
    28 	('&lt;'       , '<'),
       
    29 	('&quot;'     , '"'),
       
    30 	('&amp;'      , '&'),
       
    31 ]
       
    32 
    20 def rss_remove_html(text):
    33 def rss_remove_html(text):
    21 	exp = re.compile('<[^>]*>')
    34 	text = re.sub(r'<[^>]*>', '', text)
    22 	text = exp.sub('', text)
    35 	for bad, new in html_table :
    23 	notags = text.replace('&lt;', '<').replace('&gt;', '>')
    36 		text = text.replace(bad, new)
    24 	noescape = notags.replace('&amp;', '&').replace('&lt;', '<').replace('&gt;', '>').replace('&quot;', '"')
    37 	return text
    25 	noescape = noescape.replace('&lt;p&gt;', '')
       
    26 	noescape = noescape.replace('&lt;/p&gt;', '')
       
    27 	noescape = noescape.replace('&lt;p /&gt;', '').replace('&lt;p/&gt;', '')
       
    28 	return noescape
       
    29 
       
    30 """ OLD CODE: REMOVE LATER IF NEW FUNCTION (added 2005-10-12) WORKS
       
    31 def rss_remove_html(text):
       
    32 	notags = text.replace('&lt;', '<').replace('&gt;', '>')
       
    33 	noescape = notags.replace('&amp;', '&').replace('&lt;', '<').replace('&gt;', '>').replace('&quot;', '"')
       
    34 	noescape = noescape.replace('&lt;p&gt;', '')
       
    35 	noescape = noescape.replace('&lt;/p&gt;', '')
       
    36 	noescape = noescape.replace('&lt;p /&gt;', '').replace('&lt;p/&gt;', '')
       
    37 	return noescape
       
    38 """
       
    39 
    38 
    40 def rss_update_file():
    39 def rss_update_file():
    41 	global RSS_CACHE
    40 	global RSS_CACHE
    42 	write_file(RSS_CACHE_FILE, str(RSS_CACHE))
    41 	write_file(RSS_CACHE_FILE, str(RSS_CACHE))
    43 
    42