def test_missing_client_id_v2(self): with self.assertRaises(DAAuthException): DirectAccessV2( api_key=os.environ.get("DIRECTACCESS_API_KEY"), client_id=None, client_secret=os.environ.get("DIRECTACCESS_CLIENT_SECRET"), log_level=LOG_LEVEL)
def load(endpoint, **options): """ A generic load function that will be called by each of the three processes. :param endpoint: the Direct Access API endpoint :param options: the query parameters to provide on the endpoint :return: """ # Create a DirectAccessV2 client within the function, providing it our already existing access token # and thus avoiding unnecessary authentication calls client = DirectAccessV2( api_key=os.getenv('DIRECTACCESS_API_KEY'), client_id=os.getenv('DIRECTACCESS_CLIENT_ID'), client_secret=os.getenv('DIRECTACCESS_CLIENT_SECRET'), access_token=ACCESS_TOKEN) count = None with open(endpoint + '.csv', mode='w') as f: writer = csv.writer(f) for i, row in enumerate(client.query(endpoint, **options), start=1): count = i if count == 1: writer.writerow(row.keys()) writer.writerow(row.values()) if count % options.get('pagesize', 100000) == 0: print('Wrote {} records for {}'.format(count, endpoint)) print('Completed writing {}. Final count: {}'.format(endpoint, count)) return
def set_token_v2(): if not os.environ.get("DIRECTACCESS_TOKEN"): os.environ["DIRECTACCESS_TOKEN"] = DirectAccessV2( client_id=os.environ.get("DIRECTACCESS_CLIENT_ID"), client_secret=os.environ.get("DIRECTACCESS_CLIENT_SECRET"), api_key=os.environ.get("DIRECTACCESS_API_KEY"), ).access_token return
def create_directaccess_v2(): return DirectAccessV2( api_key=os.environ.get("DIRECTACCESS_API_KEY"), client_id=os.environ.get("DIRECTACCESS_CLIENT_ID"), client_secret=os.environ.get("DIRECTACCESS_CLIENT_SECRET"), access_token=os.environ.get("DIRECTACCESS_TOKEN"), retries=5, backoff_factor=10, log_level=LOG_LEVEL)
Then, we're filtering the responses down to those records that have had their production allocated using Drillinginfo's production allocation algorithm and where LowerPerf values exist and are greater than or equal to 2000 and UpperPerf values exist and are less than or equal to 3000. """ import os try: # Use the memory-efficient ifilter function available in itertools for Python 2 from itertools import ifilter as filter except ImportError: # The built in filter function returns a generator in Python 3 pass from enverus_developer_api import DirectAccessV2 # Initialize our Direct Access object d2 = DirectAccessV2(api_key=os.getenv('DIRECTACCESS_API_KEY'), client_id=os.getenv('DIRECTACCESS_CLIENT_ID'), client_secret=os.getenv('DIRECTACCESS_CLIENT_SECRET')) # Build the API query query = d2.query('producing-entities', pagesize=10000, deleteddate='eq(null)', state='TX') # Build the client-side filter rows = filter( lambda x: x['AllocPlus'] == 'Y' and x['LowerPerf'] is not None and x[ 'LowerPerf'] >= 2000 and x['UpperPerf'] is not None and x['UpperPerf'] <= 3000, query) # Execute the query and filter the responses