|
Revision 55, 1.2 kB
(checked in by verbosus, 22 months ago)
|
|
Removed htmlescape in favor of cgi.escape (thanks, C8E)
|
| Line | |
|---|
| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | |
|---|
| 3 | """Statusbot, a GTalk-based (Jabber) status publisher |
|---|
| 4 | """ |
|---|
| 5 | |
|---|
| 6 | import re |
|---|
| 7 | from cgi import escape |
|---|
| 8 | import time, sys, codecs |
|---|
| 9 | import jabberbot |
|---|
| 10 | |
|---|
| 11 | __author__ = "Antonio Cavedoni <antonio@cavedoni.org>" |
|---|
| 12 | __svnid__ = "$Id$" |
|---|
| 13 | |
|---|
| 14 | def extract_link(input): |
|---|
| 15 | link_r = re.compile(r'(?P<desc>.*?): (?P<uri>(http://.*)+)') |
|---|
| 16 | results = link_r.search(input) |
|---|
| 17 | if results: |
|---|
| 18 | return u'<a href="%s">%s</a>' % \ |
|---|
| 19 | (results.group('uri'), escape(results.group('desc'))) |
|---|
| 20 | else: |
|---|
| 21 | return escape(input) |
|---|
| 22 | |
|---|
| 23 | def save_status(status): |
|---|
| 24 | """Write status (a unicode string) to filename (as UTF-8)""" |
|---|
| 25 | template = codecs.open('/path/to/template.html', 'r', 'utf-8') |
|---|
| 26 | t = template.read() |
|---|
| 27 | f = codecs.open('/path/to/output.html', 'w', 'utf-8') |
|---|
| 28 | status = extract_link(status) |
|---|
| 29 | f.write(t.replace(u'{{ status }}', status)) |
|---|
| 30 | template.close() |
|---|
| 31 | f.close() |
|---|
| 32 | |
|---|
| 33 | if __name__ == "__main__": |
|---|
| 34 | statusbot = jabberbot.JabberBot('username', 'password') |
|---|
| 35 | statusbot.connect() |
|---|
| 36 | for x in xrange(10): |
|---|
| 37 | statusbot.check_events() |
|---|
| 38 | status = statusbot.roster.getStatus('jabberid') |
|---|
| 39 | if status: |
|---|
| 40 | save_status(status) |
|---|
| 41 | sys.exit(0) |
|---|
| 42 | time.sleep(0.5) |
|---|