Skip to main content
![version](http://img.shields.io/pypi/v/lds_org.svg)
![license](http://img.shields.io/pypi/l/lds_org.svg)
![Travis](https://img.shields.io/travis/jidn/LDS-org.svg)
![coverage](https://coveralls.io/repos/github/jidn/lds_org/badge.svg?branch=master)

# LDS-org

Most times, I can quickly jump the LDS.org website and get the exact
information I need. However, there are those repeated tasks I don't
really want to to run time and time again. Hmm... sounds like a job
for a computer.

In my current role as Clerk, reports and information are my life. I
want to make it easier to get that information.

## Install

For install you can use pip:

```sh
pip install lds-org
```

## QuickStart

Using the command line, see the available endpoints and your current ID.

```sh
python -m lds_org
python -m lds_org -e current-user-id
```

Now lets get the same in python.

```python
import lds_org

lds = lds_org.LDSOrg()
lds.signin(username, password)
rv = lds.get('current-user-id')
print(rv.json())
```

To make conneciton a bit easier, we can create a session for repeated use.

```python
with lds_org.session() as lds:
rv = lds.get(some_context_of_interest)
...
```

## Endpoints

Endpoints are URLs to resources, most of which provide JSON.
The list of endpoints are found at <https://tech.lds.org/mobile/ldstools/config.json> and are somewhat documented at <https://tech.lds.org/wiki/LDS_Tools_Web_Services>.

Some endpoints need additional data, usually the unit number which appears as `%@` in the endpoints found at [tech.lds.org](https://tech.lds.org/mobile/ldstools/config.json).
However, tech.lds.org uses it for other items as well.
I alter the URLs for better understanding by replace `%@` with `{unit}` and `{member}` as I currently understand the the endpoints.

The module will automatically replace `{unit}` with the authorized users unit number if it is not provided. You can also provide a unit number for a different unit in a stake.

For example, get the number of household in the stake by unit.

```python
Unit = collections.namedtuple('Unit', 'name number')
with lds_org.session() as lds:
rv = lds.get('stake-units')
data = rv.json()
units = sorted(Unit(_['wardName'], _['wardUnitNo'])
for _ in data)
for unit in units:
rv = lds.get('unit-membership', unit=unit.number)
print('{:4} [unit {}]{}'.format(len(rv.json()), unit.number, unit.name))
```

You can also pass in `unit` and `member` information on the command line. See the help at

```sh
python -m lds_org -h
```

### Photos

The `photo-url` endpoint needs two arguments, an member ID and the type of photo. The photo type is either 'household' or 'individual'. See [LDS Tools Web Services](https://tech.lds.org/wiki/LDS_Tools_Web_Services#Signin_services) for more information.

```python
from pprint import pprint

# Get my personal picture
with lds_org.session() as lds:
rv = lds.get('current-user-id')
my_id = rv.json()
rv = lds.get('photo-url', 'individual', member=my_id)
pprint(rv.json())
```

If you know the member ID (use endpoint `current-user-id` for yourself), you can do it from the command line as well with

```sh
python -m lds_org -e current-user-id
python -m lds_org -e photo-url -m memberId individual
```

### JSON

When asking for endpoint information from the command line, the output is pretty printed.
However, you may want to take the information and use it. You want the output in JSON.
Using the command line option of `-j` the endpoint data is given as JSON.

### Secure your username and password

You need to keep your username and password secret. However, you also
want to automate the process of getting and processing information
from LDS.org. You could put your username and password in your code,
but the possibility of sharing your information is very possible when
you show or share your code.

This module can use environment variables containing your username and
password. In \*nix based systems, you can add the following to your
.bashrc or its equivelent.

```sh
export LDSORG_USERNAME=username
export LDSORG_PASSWORD="password"
```

Personally, I create a seperate file to fix the command line environment.
I take the above and put it in a file 'ldsorg-password.sh'. From the
command line, type the following and you should see your LDS.org username.

```sh
source ldsorg-password.sh
echo $LDSORG_USERNAME
```

Once this is done, you no longer need to either enter your credentials from
the command line or specify a username/password in your code.

Metadata

Release files for LDS-org 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for LDS-org 0.2.1
File Size Uploaded Provenance Actions
LDS-org-0.2.1.tar.gz 7.4 kB Without provenance Details for LDS-org-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for LDS-org 0.2.1
File Interpreter ABI Platform Actions
LDS_org-0.2.1-py3-none-any.whl Python 3 none any Details for LDS_org-0.2.1-py3-none-any.whl

Total release size: 17.4 kB

Release files / LDS-org-0.2.1.tar.gz

Download URL LDS-org-0.2.1.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
05b1cb61f71dbba8e3f397e4cb4b73dd3ee3b3bcebe1bfe3a3dbde9312a2012b
BLAKE2b-256 checksum
How to use checksums
12f0b611fc6e3984ae0f8f21f4431062ace25c59b708879a49c8b7555e16366d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / LDS_org-0.2.1-py3-none-any.whl

Download URL LDS_org-0.2.1-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0a769de07561bc97cd7751a6393e07d1a06bf84f22cf482afe0d238c6111a8d7
BLAKE2b-256 checksum
How to use checksums
fe96e4c9e718d551bd2f54d611595bce3e63ea236688aedcd1e62fe4c54394aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for LDS-org 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page