Skip to content

Commit

Permalink
#2: initial commit of WSLCB Portal class
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoryfoster committed Dec 5, 2017
1 parent fac99e4 commit 59248ab
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 13 deletions.
5 changes: 3 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ python_version = "3.6"

[packages]

sodapy = "*"
# testpackage = "*"


Expand All @@ -29,8 +30,8 @@ coverage = "~=4.0"
"coverage.space" = "~=0.8"
mkdocs = "*"
docutils = "*"
Pygments = "*"
pygments = "*"
wheel = "*"
PyInstaller = "*"
pyinstaller = "*"
twine = "*"
sniffer = "*"
37 changes: 29 additions & 8 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cannapy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""cannapy package root."""
"""cannapy module."""

from .organization import Organization

__project__ = 'cannapy'
__version__ = '0.0.0'

VERSION = "{0} v{1}".format(__project__, __version__)

from .organization import Organization
3 changes: 3 additions & 0 deletions cannapy/organization.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""A class representing an organization."""


class Organization(object):
"""An organization.
Expand Down
1 change: 1 addition & 0 deletions cannapy/us/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""cannapy submodule for the United States."""
1 change: 1 addition & 0 deletions cannapy/us/wa/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""cannapy submodule for Washington state."""
1 change: 1 addition & 0 deletions cannapy/us/wa/wslcb/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""cannapy submodule for Washington State Liquor & Cannabis Board (WSLCB)."""
60 changes: 60 additions & 0 deletions cannapy/us/wa/wslcb/portal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""An interface to the WSLCB Socrata-based open data portal."""

import os
import time
from sodapy import Socrata

# WSLCB Socrata Open Data Portal URL
WSLCB_PORTAL_URL = 'data.lcb.wa.gov'

# WSLCB Socrata Open Data Portal Dataset IDs
WSLCB_PORTAL_DATASETS = {
'licensed_businesses': 'bhbp-x4eb',
}


class WSLCBPortal(object):
"""A class interface to the WSLCB open data portal."""

def __init__(self, app_token=''):
"""Constructor."""
# Set the user's Socrata app token:
# https://dev.socrata.com/docs/app-tokens.html
if app_token == '':
# See if an environment variable is set
app_token = os.getenv('WSLCB_APP_TOKEN', '')
self._app_token = app_token

# The Socrata client property will be initialized on first get
self._client = None

def dataset_last_updated(self, dataset_id):
"""Return the requested dataset's last update timestamp."""
# Retrieve the source dataset's metadata
metadata = self.client.get_metadata(dataset_id)

# Retrieve dataset last update timestamp in epoch/Unix time
last_updated = metadata['rowsUpdatedAt']

# Convert to a localized Python time.struct_time
# https://docs.python.org/3/library/time.html#time.struct_time
last_updated = time.localtime(last_updated)

return last_updated

@property
def app_token(self):
"""The user's Socrata open data portal app token."""
return self._app_token

@app_token.setter
def app_token(self, value):
self._app_token = value

@property
def client(self):
"""A sodapy client interface to the WSLCB Socrata open data portal."""
if self._client is None:
self._client = Socrata(WSLCB_PORTAL_URL, self.app_token)

return self._client

0 comments on commit 59248ab

Please sign in to comment.