Changeset 55
- Timestamp:
- 12/14/06 20:22:07 (2 years ago)
- Files:
-
- 1 modified
-
hacks/trunk/statusbot/statusbot.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
hacks/trunk/statusbot/statusbot.py
r54 r55 5 5 6 6 import re 7 from cgi import escape 7 8 import time, sys, codecs 8 9 import jabberbot … … 11 12 __svnid__ = "$Id$" 12 13 13 def htmlescape(input):14 return input.replace('&', '&').replace('<', '<').replace('>', '>')15 16 14 def extract_link(input): 17 15 link_r = re.compile(r'(?P<desc>.*?): (?P<uri>(http://.*)+)') … … 19 17 if results: 20 18 return u'<a href="%s">%s</a>' % \ 21 (results.group('uri'), htmlescape(results.group('desc')))19 (results.group('uri'), escape(results.group('desc'))) 22 20 else: 23 return htmlescape(input)21 return escape(input) 24 22 25 23 def save_status(status): 26 24 """Write status (a unicode string) to filename (as UTF-8)""" 27 template = codecs.open( 28 '/path/to/template.html', 'r', 'utf-8') 25 template = codecs.open('/path/to/template.html', 'r', 'utf-8') 29 26 t = template.read() 30 f = codecs.open( 31 '/path/to/output.html', 'w', 'utf-8') 27 f = codecs.open('/path/to/output.html', 'w', 'utf-8') 32 28 status = extract_link(status) 33 29 f.write(t.replace(u'{{ status }}', status))