Read Daily Bread easier with python

I live in Malaysia which is GMT+8.

When I open the Daily Bread in the morning, it shows me the previous day’s devotion because Malaysia’s time zone is ahead of Daily Bread’s. However, Daily Bread allows me to read ‘ahead’ by clicking on any date on a calendar on the website.

Well, I don’t like to do anything manual repeatedly if I can help it and I wrote the script below.

 
import os
import datetime
import webbrowser
import urllib2
from BeautifulSoup import BeautifulSoup
 
def daily_bread(d):
    year = d.year
    month = d.month
    day = d.day
# refer http://my.php.net/manual/en/function.sprintf.php for sprintf format
 
    url = 'http://www.rbc.org/devotionals/our-daily-bread/%04d/%02d/%02d/devotion.aspx' % (year, month, day)
    webbrowser.open(url)
 
    open_bible(url)
 
 
def open_bible(daily_page_url):
    page = urllib2.urlopen(daily_page_url)
    s = BeautifulSoup(page)
 
    bible_a = s.find('a', id = 'ctl00_cphPrimary_hlGatewayVerse')
    url = bible_a['href']
    webbrowser.open(url)
 
 
today = datetime.date.today()
 
daily_bread(today)
 
if today.weekday() == 5: # Saturday
    tomorrow = today + datetime.timedelta(1)
    daily_bread(tomorrow)

It will open the Daily Bread devotion for the correct day (the same day as my computer time).

As a bonus, it will also open the day’s Bible verse. (You will need to easy_install BeautifulSoup first).

On Saturdays, I read the Sunday’s devotion too because I go to church on Sunday. The script opens 2 days’ reading on Saturday.

Technorati tags: ,
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Furl
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)