test

Find out how many members of your stake have a calling

This is a little bit technical but I'll try to break it down into the simplest steps I can, also it shouldn't take much more than 5-10 minutes to complete all these steps.

First open up an online python interpreter like this one 

Then on the left hand side of the screen paste the python code from here

import json
import requests

#javascritp to get unit 
#  window.location.href.substring(window.location.href.lastIndexOf('/')+1)
unit=''

#javascirpt to get directory_access_token
#  document.cookie.match(new RegExp('(^| )directory_access_token=([^;]+)'))[2]
directoryAccessToken=''

#javascript to get directory_identity_token
#  document.cookie.match(new RegExp('(^| )directory_identity_token=([^;]+)'))[2]
directoryIdentityToken=''

#have to get bearer from developer tools
bearer=''

def parseWardData(jsonData):
    membersInWard = 0
    membersWithCalling = 0
    membersWithoutCalling = 0
    membersWithMultipleCallings = 0
    membersWithStakeCallings = 0
    visibleChildrenRecordsInWard = 0

    #loop over each household
    for houseHold in jsonData:
        #loop over each member, count each member
        if "members" in houseHold and isinstance(houseHold["members"], listand len(houseHold["members"]) > 0:
            for member in houseHold["members"]:
                countThePositionForThisMember = True
                if member["head"] == True:
                    membersInWard = membersInWard + 1

                    if "positions" in member and isinstance(member["positions"], listand len(member["positions"]) > 0:
                        if len(member["positions"]) > 1:
                            membersWithMultipleCallings = membersWithMultipleCallings + 1
                        
                        for position in member["positions"]:
                            if countThePositionForThisMember:
                                membersWithCalling = membersWithCalling + 1
                                countThePositionForThisMember = False
                            if position["unitNumber"] != member["unitNumber"]:
                                membersWithStakeCallings = membersWithStakeCallings + 1
                    else:
                        membersWithoutCalling = membersWithoutCalling + 1
                else:
                    visibleChildrenRecordsInWard = visibleChildrenRecordsInWard + 1

    print("Adult members in ward: " + str(membersInWard))
    print("Adult members with callings: " + str(membersWithCalling))
    print("Adult members without a calling: " + str(membersWithoutCalling))
    print("Adult members with multiple callings: " + str(membersWithMultipleCallings))
    print("Adult members in the ward with Stake callings: " + str(membersWithStakeCallings))
    print("Average estimated adult activity in ward: " + str(membersWithCalling / membersInWard))
    
    return membersInWardmembersWithCalling
    

membersInStake = 0
membersInStakeWithCalling = 0

cookies = {'directory_access_token':directoryAccessToken+';''directory_identity_token':directoryIdentityToken+';'}
headers = {'authorization''Bearer ' + bearer}
r = requests.get('https://directory.churchofjesuschrist.org/api/v4/units/'+unitheaders=headerscookies=cookies)
stakeData = json.loads(r.text)
#print("stake: " + str(stakeData))
if 'childUnits' in stakeData:
    childUnits = stakeData['childUnits']
    #print("childUnits: " + str(childUnits))
    for childUnit in childUnits:
        #print("childUnit: " + str(childUnit))
        unitNumber = childUnit['unitNumber']
        r = requests.get('https://directory.churchofjesuschrist.org/api/v4/households?unit='+str(unitNumber), headers=headerscookies=cookies)
        ward = json.loads(r.text)
        #print("ward: " + str(ward))
        membersInWardmembersWithCalling = parseWardData(json.loads(r.text))
        membersInStakeWithCalling = membersInStakeWithCalling + membersWithCalling
        membersInStake = membersInStake + membersInWard

print("Adult members in Stake: " + str(membersInStake))
print("Adult members in Stake with callings: " + str(membersInStakeWithCalling))
print("Average estimated adult activity in stake: " + str(membersInStakeWithCalling / membersInStake))



 At the top of that program you'll see the following

#javascritp to get unit 
#  window.location.href.substring(window.location.href.lastIndexOf('/')+1)
unit=''

#javascirpt to get directory_access_token
#  document.cookie.match(new RegExp('(^| )directory_access_token=([^;]+)'))[2]
directoryAccessToken=''

#javascript to get directory_identity_token
#  document.cookie.match(new RegExp('(^| )directory_identity_token=([^;]+)'))[2]
directoryIdentityToken=''

#have to get bearer from developer tools
bearer=''
You need to fill these in for the program to work, once they are filled in you can press the run button and on the right hand side of the screen the results will be printed. Those results will only show you how many adults in your stake have a calling and how many are on the records without a calling. Children are not counted.

Now for the tricky part, filling in the required fields so the program can run. 

Using Firefox or Chrome do the following

1) Log in to lds.org, if you don't have a login then you can't do this

2) Navigate to the Directory, you can just go to this link after logging in, https://directory.churchofjesuschrist.org/

3) Open the developer tools by pressing F12 on your keyboard, then click on the Network tab in developer tools



4) Change the drop down on the top left from your ward to "Entire Stake"



5) In the developer tools there is a filter box, in that box type "households", now in the list you should only see a few requests for the households in the various wards in your stake. 




6) click on one and get the Authorization bearer token from the request headers, you will probably have to scroll down on the right hand side, you need to look for "Authorization: Bearer " and then copy the long block of text after Bearer until the next field, in this case you can see the next field is "Connection: keep-alive"




7) paste just the token after the word Bearer into the python program into the field called bearer. So it should look like bearer='somelongrandomstring' when you are done

8) Run the three javascript commands in the console to get the other three values you need for the script to work. Copy each string and paste it into the console and then press enter.

This will get you the unit

window.location.href.substring(window.location.href.lastIndexOf('/')+1)

This will get you the directoryAccessToken

document.cookie.match(new RegExp('(^| )directory_access_token=([^;]+)'))[2]

This will get you the directoryIdentityToken

document.cookie.match(new RegExp('(^| )directory_identity_token=([^;]+)'))[2]





9) Run the script and the results will print on the right.

The results will look something like this
Adult members in ward: 202
Adult members with callings: 109                                       
Adult members without a calling: 93
Adult members with multiple callings: 27
Adult members in the ward with Stake callings: 18
Visible children records in the ward: 15
Average estimated adult activity in ward: 0.5396039603960396
Adult members in ward: 178
Adult members with callings: 87
Adult members without a calling: 91
Adult members with multiple callings: 19
Adult members in the ward with Stake callings: 18
Visible children records in the ward: 155
Average estimated adult activity in ward: 0.4887640449438202

You can see in these two wards about half of the adults have a calling, the other half may or may not be active but they don't currently hold a calling.