import os

from luigi import Parameter
from ob_airtable import get_record_by_name, get_record

AIRTABLE_EXPT_TABLE = 'Genomics%20Expt'
AIRTABLE_SAMPLE_TABLE = 'Genomics%20Sample'

S3_BUCKET = os.environ.get('S3_BUCKET')


def get_samples(expt_id):
    expt = get_record_by_name(expt_id, AIRTABLE_EXPT_TABLE)
    sample_keys = expt['fields']['Genomics samples']

    for sample_key in sample_keys:
        sample = get_record(sample_key, AIRTABLE_SAMPLE_TABLE)
        yield sample['fields']['Name']


class Sample(object):

    sample_id = Parameter()

    @property
    def sample(self):
        if not hasattr(self, '_sample'):
            self._sample = get_record_by_name(self.sample_id, AIRTABLE_SAMPLE_TABLE)['fields']
        return self._sample

    @property
    def sample_folder(self):
        return '{expt}/{sample}'.format(
            bucket=S3_BUCKET,
            expt = self.experiment['Name'],
            sample=self.sample_id)

    @property
    def experiment(self):
        if not hasattr(self, '_experiment'):
            expt_key = self.sample['Experiment'][0]
            self._experiment = get_record(expt_key, AIRTABLE_EXPT_TABLE)['fields']
        return self._experiment

import os

from luigi import Parameter
from ob_airtable import AirtableClient

AIRTABLE_EXPT_TABLE = 'Genomics%20Expt'
AIRTABLE_SAMPLE_TABLE = 'Genomics%20Sample'

S3_BUCKET = os.environ.get('S3_BUCKET')

client = AirtableClient()

def get_samples(expt_id):
    expt = client.get_record_by_name(expt_id, AIRTABLE_EXPT_TABLE)
    sample_keys = expt['fields']['Genomics samples']

    for sample_key in sample_keys:
        sample = client.get_record(sample_key, AIRTABLE_SAMPLE_TABLE)
        yield sample['fields']['Name']


class Sample(object):

    sample_id = Parameter()

    @property
    def sample(self):
        if not hasattr(self, '_sample'):
            self._sample = client.get_record_by_name(self.sample_id, AIRTABLE_SAMPLE_TABLE)['fields']
        return self._sample

    @property
    def sample_folder(self):
        return '{expt}/{sample}'.format(
            bucket=S3_BUCKET,
            expt = self.experiment['Name'],
            sample=self.sample_id)

    @property
    def experiment(self):
        if not hasattr(self, '_experiment'):
            expt_key = self.sample['Experiment'][0]
            self._experiment = client.get_record(expt_key, AIRTABLE_EXPT_TABLE)['fields']
        return self._experiment

Update to match changes in ob-airtable
Update to match changes in ob-airtable

  import os
  
  from luigi import Parameter
- from ob_airtable import get_record_by_name, get_record
+ from ob_airtable import AirtableClient
  
  AIRTABLE_EXPT_TABLE = 'Genomics%20Expt'
  AIRTABLE_SAMPLE_TABLE = 'Genomics%20Sample'
  
  S3_BUCKET = os.environ.get('S3_BUCKET')
  
+ client = AirtableClient()
  
  def get_samples(expt_id):
-     expt = get_record_by_name(expt_id, AIRTABLE_EXPT_TABLE)
+     expt = client.get_record_by_name(expt_id, AIRTABLE_EXPT_TABLE)
      sample_keys = expt['fields']['Genomics samples']
  
      for sample_key in sample_keys:
-         sample = get_record(sample_key, AIRTABLE_SAMPLE_TABLE)
+         sample = client.get_record(sample_key, AIRTABLE_SAMPLE_TABLE)
          yield sample['fields']['Name']
  
  
  class Sample(object):
  
      sample_id = Parameter()
  
      @property
      def sample(self):
          if not hasattr(self, '_sample'):
-             self._sample = get_record_by_name(self.sample_id, AIRTABLE_SAMPLE_TABLE)['fields']
+             self._sample = client.get_record_by_name(self.sample_id, AIRTABLE_SAMPLE_TABLE)['fields']
          return self._sample
  
      @property
      def sample_folder(self):
          return '{expt}/{sample}'.format(
              bucket=S3_BUCKET,
              expt = self.experiment['Name'],
              sample=self.sample_id)
  
      @property
      def experiment(self):
          if not hasattr(self, '_experiment'):
              expt_key = self.sample['Experiment'][0]
-             self._experiment = get_record(expt_key, AIRTABLE_EXPT_TABLE)['fields']
+             self._experiment = client.get_record(expt_key, AIRTABLE_EXPT_TABLE)['fields']
          return self._experiment
  
Update to match changes in ob-airtable
## Code Before:
import os

from luigi import Parameter
from ob_airtable import get_record_by_name, get_record

AIRTABLE_EXPT_TABLE = 'Genomics%20Expt'
AIRTABLE_SAMPLE_TABLE = 'Genomics%20Sample'

S3_BUCKET = os.environ.get('S3_BUCKET')


def get_samples(expt_id):
    expt = get_record_by_name(expt_id, AIRTABLE_EXPT_TABLE)
    sample_keys = expt['fields']['Genomics samples']

    for sample_key in sample_keys:
        sample = get_record(sample_key, AIRTABLE_SAMPLE_TABLE)
        yield sample['fields']['Name']


class Sample(object):

    sample_id = Parameter()

    @property
    def sample(self):
        if not hasattr(self, '_sample'):
            self._sample = get_record_by_name(self.sample_id, AIRTABLE_SAMPLE_TABLE)['fields']
        return self._sample

    @property
    def sample_folder(self):
        return '{expt}/{sample}'.format(
            bucket=S3_BUCKET,
            expt = self.experiment['Name'],
            sample=self.sample_id)

    @property
    def experiment(self):
        if not hasattr(self, '_experiment'):
            expt_key = self.sample['Experiment'][0]
            self._experiment = get_record(expt_key, AIRTABLE_EXPT_TABLE)['fields']
        return self._experiment

## Instruction:
Update to match changes in ob-airtable
## Code After:
import os

from luigi import Parameter
from ob_airtable import AirtableClient

AIRTABLE_EXPT_TABLE = 'Genomics%20Expt'
AIRTABLE_SAMPLE_TABLE = 'Genomics%20Sample'

S3_BUCKET = os.environ.get('S3_BUCKET')

client = AirtableClient()

def get_samples(expt_id):
    expt = client.get_record_by_name(expt_id, AIRTABLE_EXPT_TABLE)
    sample_keys = expt['fields']['Genomics samples']

    for sample_key in sample_keys:
        sample = client.get_record(sample_key, AIRTABLE_SAMPLE_TABLE)
        yield sample['fields']['Name']


class Sample(object):

    sample_id = Parameter()

    @property
    def sample(self):
        if not hasattr(self, '_sample'):
            self._sample = client.get_record_by_name(self.sample_id, AIRTABLE_SAMPLE_TABLE)['fields']
        return self._sample

    @property
    def sample_folder(self):
        return '{expt}/{sample}'.format(
            bucket=S3_BUCKET,
            expt = self.experiment['Name'],
            sample=self.sample_id)

    @property
    def experiment(self):
        if not hasattr(self, '_experiment'):
            expt_key = self.sample['Experiment'][0]
            self._experiment = client.get_record(expt_key, AIRTABLE_EXPT_TABLE)['fields']
        return self._experiment
