Saturday, March 05, 2011

Downloading Our Daily Bread Devotions

Typically, I like to read my devotions at work during a quick noon-time break. Unfortunately, the RBC website is blocked at work. Although I could just order Our Daily Bread in printed form, they have a Java Mobile Application that you can download and then install on your smart phone. Since I own an ancient XV6700, I use the Esmertec Java Runtime to install and run these applications. So, wanting to automate this manual process to some degree, I wrote a Powershell script to download the jar file from the website and then copy the file onto the memory card of my docked XV6700. The code is as follows (feel free to reuse):

#Script to download latest devotionals for the month
#Copyright 2011 Michael Robbeloth
function getODB ()
{
# Load PSMobile add-in, find it at http://psmobile.codeplex.com/#
# WARNING Add-in only supports 32-bit Powershell
Add-PSSnapIn PSMobile

# Setup, target puts the jar directly on my smartphone memory card
# provided it's in the dock
$cInt = new-object System.Net.WebClient
$date = Get-Date
$jarname = "MobileDevos.jar"
$target = "c:\temp\" + $jarname
$year = $date.Year
if ($date.Month -lt 10) {
$month = "0" + $date.Month
}
else {
$month = $date.Month
}

#$target = "Mobile:\Storage Card"

# For a generic target, use a temp directory
#$target = "c:\temp\" + $jarname

# Build url to access
# http://www.rbc.org/mobile/apps///MobileDevos.jar
$url = "http://www.rbc.org/mobile/apps/" + $year + "/" + $month + "/" +

$jarname

# Download devotional jars for the month
write-host 'transfering from' $url 'to' $target
try {
$cInt.DownloadFile($url, $target)
}
catch {
Write-Host $_.Exception.ToString()
}

$copySrc = $target
$copyDest = "Mobile:\Storage Card"
write-host copying $copySrc to $copyDest
ConvertTo-WMFile -Force C:\temp\MobileDevos.jar -destination 'Mobile:\Storage Card'
}

There are three downsides to this process:
1. You have to use the 32-bit Powershell with the aging PSMobile add-in
2. I don't know how to automate the actual installation of the jar file in Esmertec. However, this is a minor point for a monthly activity
3. If RBC changes their scheme for storing these jar files, I'll have to adjust the code.


It will then be necessary to schedule an automated task in Windows scheduler to run this script on the first day of every month. The application path to use is:

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe

The command line argument to pass is:

"&'C:\Users\UserName\Documents\Scripts\Powershell\kickstartODB.ps1'"

Note that I did not pass the filename of the getODB script. I wrote another small script to kickstart the other one:



cd 'C:\Users\Username\Documents\Scripts\Powershell\'
. ./getODB
getODB



It probably goes without saying, but you should replace username with your acutal Windows account username.

I hope someone finds this script to be useful.

Michael

0 Comments:

Post a Comment

<< Home