Page 1 of 1

Stake and Ward API

Posted: Thu Oct 15, 2009 12:00 pm
by tjallred
I'm creating a website geared towards members of the Church that would
allow registered users to optionally specify their Stake/Mission and Ward/Branch.

Is there any sort of web service (REST/SOAP/XML/screen scraping) that I could use to let users pick their stake/mission and ward/branch?

Trevor

Posted: Thu Oct 15, 2009 12:15 pm
by RossEvans
tallred wrote:I'm creating a website geared towards members of the Church that would
allow registered users to optionally specify their Stake/Mission and Ward/Branch.

Is there any sort of web service (REST/SOAP/XML/screen scraping) that I could use to let users pick their stake/mission and ward/branch?

There is no API.

The only thing I can think of is that you could make the user enter their LDS Account username and password, and log them into LUWS. Technically you then could scrape the screens to harvest the names of their units.

If all you do with the harvested data is handled client-side, that might be okay policywise. But I think harvesting anything from LUWS and storing it on your server would be coloring outside the lines.

Posted: Thu Oct 15, 2009 1:33 pm
by russellhltn
I'd be leery about giving my LDS Account information to a non-church server. I'd have no idea what's being done.

Posted: Thu Oct 15, 2009 1:51 pm
by Mikerowaved
Not exactly an API, but you could bounce the user-supplied info off of HERE to get the actual links to their stake/ward websites.

Posted: Thu Oct 15, 2009 5:39 pm
by tjallred
I'll have to change this as soon as the Church changes their search screen, but it works for now. Thanks Mikerowaved for the idea.

Code: Select all

public class ScreenScraper {
	private static String LDS_SEARCH = "http://www.lds.org/units/find/search/1,16055,2311-1,00.html";
	
	static public List<Account> findStakes(String unitName) {
		List<Account> results = new ArrayList<Account>();
		
		String url = LDS_SEARCH + "?unitName=" + unitName;

		Source source = null;
		try {
			source = new Source(new URL(url));
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (source == null)
			return results;
		
		List<Element> allElements = source.getAllElements(HTMLElementName.A);
		for (Element element : allElements) {
			String link = element.getAttributeValue("href");
			Account account = new Account();
			account.setName(element.getContent().toString());
			account.setDescription(link);
			if (link.contains("secure.lds.org/units/stake")) {
				account.setType(AccountType.Stake);
				results.add(account);
			}
			if (link.contains("secure.lds.org/units/home")) {
				account.setType(AccountType.Ward);
				results.add(account);
			}
		}
		
		return results;
	}
}