Tagger plugin
"G. Vamsee Krishna" <vamsee_k-9geRo0GdX4kE71Kmvb/[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello, I've recently started using Pyblosxom and learning Python. Last night I hacked up a small plugin that would link <google></google> tags to Google search (ditto for IMDB and Wiki and for any other search engine). Inspired by John Slee's ``googletag'' plugin for Blosxom. Please let me know your opinions. Regards, Vamsee ------------ Plugin follows ------------------------------- import re # Link the text within <google></google> to Google search. Same with IMDB and Wiki. # Works for almost any search engine you can think of # Example: <google>Pyblosxom</google> in a blog entry is converted to # <a href="http://www.google.com/search?q=Pyblosxom">Pyblosxom</a> # # This is a minor hack and could be inefficient to a various degree, as this is the first # time I've done anything in Python. Hope this is useful. __author__ = "Vamsee Krishna Gomatam <[email protected]>" __description__ = "Easy linking to Google, IMDB, Wiki and anything else you can think of" def verify_installation(request): """ Just to verify if installation is fine or not """ return 1 def cb_story(args): """ Check for <google></google>, <imdb></imdb> and <wiki></wiki> tags and convert them to corresponding URLs. """ request = args["request"] data = request.getData() entry = args["entry"] body = entry["body"] entry["body"] = re.sub( "<google>([^<]*)</google>", r'<a href="http://www.google.com/search?q=\1">\1</a>', entry["body"] ) entry["body"] = re.sub( "<imdb>([^<]*)</imdb>", r'<a href="http://www.imdb.com/find?q=\1">\1</a>', entry["body"] ) entry["body"] = re.sub( "<wiki>([^<]*)</wiki>", r'<a href="http://en.wikipedia.org/wiki/?search=\1">\1</a>', entry["body"] ) --------------------------------------------------------------------------------- -- Playfully doing something difficult, whether useful or not, that is hacking. -- Richard Stallman
tagger.py
(text/plain, 1.3 KB)
import re # Link the text within <google></google> to Google search. Same with IMDB and Wiki. # Works for almost any search engine you can think of # Example: <google>Pyblosxom</google> in a blog entry is converted to # <a href="http://www.google.com/search?q=Pyblosxom">Pyblosxom</a> # # This is a minor hack and could be inefficient to a various degree, as this is the first # time I've done anything in Python. Hope this is useful. __author__ = "Vamsee Krishna Gomatam <[email protected]>" __description__ = "Easy linking to Google, IMDB, Wiki and anything else you can think of" def verify_installation(request): """ Just to verify if installation is fine or not """ return 1 def cb_story(args): """ Check for <google></google>, <imdb></imdb> and <wiki></wiki> tags and convert them to corresponding URLs. """ request = args["request"] data = request.getData() entry = args["entry"] body = entry["body"] entry["body"] = re.sub( "<google>([^<]*)</google>", r'<a href="http://www.google.com/search?q=\1">\1</a>', entry["body"] ) entry["body"] = re.sub( "<imdb>([^<]*)</imdb>", r'<a href="http://www.imdb.com/find?q=\1">\1</a>', entry["body"] ) entry["body"] = re.sub( "<wiki>([^<]*)</wiki>", r'<a href="http://en.wikipedia.org/wiki/?search=\1">\1</a>', entry["body"] )