API

The gdgps_apps package contains a number of classes designed to take the complexity out of interfacing with APPS. Rich Python applications consisting of anything from GUIs, to automated operational center infrastructure, to the simple command line interface delivered with the library can be developed with APPS as the backend engine using the Python API documented here.

Once you have the library installed and your credential downloaded to your local system, interfacing with APPS is easy using the library! For instance, to upload all files in a directory and then download the results as they become available, while warning about any errors one might write:

#!/usr/bin/env python3

from gdgps_apps.apps import APPS
from gdgps_apps import defines
import os
import time


if __name__ == '__main__':

    apps = APPS(log_level=None)

    files = {f: None for f in os.listdir(os.getcwd()) if
             os.path.isfile(os.path.join(os.getcwd(), f))}

    for f in list(files.keys()):
        print('Uploading %s...' % f)
        files[f] = apps.upload_gipsyx(f)['id']

    pause = 30
    while len(files) > 0:
        apps.list_data()
        for f in list(files.keys()):
            info = apps.detail(files[f])
            if info['state'] == defines.Data.AVAILABLE:
                path = apps.download_result(info['id'])
                print('Retrieved results for file %s, downloaded to %s. Lat, Lng = (%f, %f)' % (
                        f,
                        path,
                        info['position']['coordinates'][1],
                        info['position']['coordinates'][0]
                    )
                )
                # be kind to |APPS| delete unnecessary data
                apps.delete_data(info['id'])
                del files[f]
            elif info['state'] == defines.Data.ERROR:
                for flag in info['flags']:
                    if flag['level'] == defines.DataFlag.ERROR:
                        print('APPS encountered an error processing file %s: (%s) %s' % (
                                f,
                                flag['header'],
                                flag['detail']
                            )
                        )
                apps.delete_data(info['id'])
                del files[f]
            elif info['state'] == defines.Data.VERIFIED:
                # let |APPS| know it can go ahead and process this file with the given settings
                # up until we do this we can edit processing settings by calling `gdgps_apps.apps.APPS.update`_
                apps.approve(info['id'])

        print('Waiting on %d submissions, checking again in %d seconds...' % (len(files), pause))
        time.sleep(pause)  # pause for 30 seconds so we don't overwhelm |APPS|