""" Based around KarambaVerseOfTheDay by Jan Finell but for those who like non-christian quotes. KarambaVerseOfTheDay (c) 2003 Jan Finell Superkaramba bible-verse-of-the-day theme. Fetching verses from http://votd.christ.com/biblevotd/ !Note! Using the python textwrap module, hence it will only work with Python2.3 ### LICENSE ######################################################## This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ################################################################### """ __author__ = 'Oskar Flordal' __version__ = '0.1' # # standard modules # import karamba import re, time, urllib, textwrap # # variables & constants # class Var: """ Helper class for keeping runtime variables """ def __init__(self, **kws): self.__dict__ = kws VAR = Var(shown=False, utime=None, book='', chapter='', verse='') CHAR_W = 6 CHAR_H = 15 VERSE_MAX_WIDTH = 170 / CHAR_W # 170 is the width of the bg-image VERSE_BG_X, VERSE_BG_Y = (0,15) VERSE_COLOR = (5, 64, 78) VERSE_URL = "http://votd.christ.com/biblevotd/votd-nas.js" BOOK_CHAPTER_PATTERN = re.compile('(.+) \(NASB\)') VERSE_PATTERN = re.compile('votd1 = "(.+)

') SUP_PATTERN = re.compile('( )|()') BR_PATTERN = re.compile('(
)|(
)') DEL_PATTERN = re.compile(r'( )|(\\")') # # my own functions # def get_verse_of_the_day(): try: print '-- fetching data from url:%s --' % VERSE_URL fp = urllib.urlopen(VERSE_URL) jsData = fp.read() fp.close() except Exception,e : print 'Error fetching verse from "%s" (%s)' % (URL, e) return ('','','') print '-- parsing data --' lines = jsData.split('\n') # removing extra (first and last three lines) lines lines = lines[3:-3] # # depending on the day of the week we chose a line weekday = int(time.strftime('%w')) line = lines[weekday] try: # using regex to get the real line. bookChapterL = BOOK_CHAPTER_PATTERN.search(line).group(1).split() book = ' '.join(bookChapterL[:-1]) chapter = bookChapterL[-1] verse = VERSE_PATTERN.search(line).group(1) verse = SUP_PATTERN.sub(' * ',verse) verse = BR_PATTERN.sub('\n', verse) verse = DEL_PATTERN.sub('',verse) except Exception, e: print 'Error parsing verse "%s" (%s)' % (line, e) return ('','','') print '-- done --' return (book, chapter, verse) # # Karamba functions # def initWidget(widget): karamba.attachClickArea(widget, karamba.getThemeText(widget,'BACKGROUND')) widgetUpdated(widget) def widgetUpdated(widget): if VAR.utime is None or time.time()-VAR.utime > 80000: VAR.book, VAR.chapter, VAR.verse = get_verse_of_the_day() VAR.utime = time.time() _update(widget) def meterClicked(widget, meter, button): if VAR.verse: if VAR.shown: _hide_verse(widget) else: _show_verse(widget) karamba.redrawWidget(widget) VAR.shown = not VAR.shown # # protected methods # def _update(widget): karamba.changeText(widget, karamba.getThemeText(widget, 'BOOK'), VAR.book) karamba.changeText(widget, karamba.getThemeText(widget, 'CHAPTER'), VAR.chapter) karamba.redrawWidget(widget) def _show_verse(widget): verseL = textwrap.wrap(VAR.verse, VERSE_MAX_WIDTH) bgHeight = CHAR_H*len(verseL)+4 bgW = karamba.createImage(widget, VERSE_BG_X, VERSE_BG_Y, 'images/details_bg.png') for i in range(5, bgHeight, 8): karamba.resizeImage(widget, bgW, 180, i) karamba.redrawWidget(widget) karamba.resizeImage(widget, bgW, 180, bgHeight) karamba.redrawWidget(widget) verseW = karamba.createText(widget, VERSE_BG_X+10, VERSE_BG_Y+4, 170, bgHeight, '\n'.join(verseL)) karamba.changeTextSize(widget, verseW, 11) karamba.changeTextColor(widget, verseW, *VERSE_COLOR) VAR.verseW = verseW VAR.bgW = bgW def _hide_verse(widget): karamba.hideImage(widget, VAR.bgW) karamba.hideText(widget, VAR.verseW) karamba.deleteImage(widget, VAR.bgW) karamba.deleteText(widget, VAR.verseW) VAR.verseW = VAR.bgW = None