Skip to content
This repository has been archived by the owner on Jan 17, 2024. It is now read-only.

Commit

Permalink
Tested new common class on company endpoint function through IEXStock…
Browse files Browse the repository at this point in the history
… class - working
  • Loading branch information
MichaelPHartmann committed Feb 8, 2022
1 parent d8ef722 commit 6face0d
Show file tree
Hide file tree
Showing 23 changed files with 60 additions and 28 deletions.
2 changes: 1 addition & 1 deletion FinMesh.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: FinMesh
Version: 2.0.1
Version: 2.0.9
Summary: A Python wrapper to bring together various financial APIs.
Home-page: UNKNOWN
Author: Michael and Josh Hartmann
Expand Down
32 changes: 23 additions & 9 deletions FinMesh/iex/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ class iexCommon():
:type external: Boolean or String. Default is False, insert token here to bypass using environment variables.
"""

def __init__(self, endpoint, symbol, external=False):
def __init__(self, section, symbol, endpoint, external=False):
self.url = f'iexapis.com/stable/{section}/{symbol}/{endpoint}?'
if external not False:
if not external == False:
self.token = external
self.parse_token_sandbox(self.token)
else:
self.sandbox_state = self.get_env_sandbox()
self.token = self.get_env_token()
if sandbox_state is True:
if self.sandbox_state is True:
self.url = 'https://sandbox.' + self.url
else:
self.url = 'https://cloud.' + self.url
Expand Down Expand Up @@ -121,14 +121,19 @@ def get_env_token(self):
Variable name is either 'IEX_SANDBOX_TOKEN' or 'IEX_TOKEN'
Whether the sandbox or production token is retrieved is determined by the environment SANDBOX state.
"""
if sandboxState:
if self.sandbox_state:
token = os.getenv('IEX_SANDBOX_TOKEN')
else:
token = os.getenv('IEX_TOKEN')
return token

def append_subdirectory_to_url(self, *subdir):
subdirectory_to_add = F"/{subdir}?"
self.url = self.url.replace("?", subdirectory_to_add)
return self.url

# Adds query paramters to the url
def add_query_params_to_url(self, **query_params):
def append_query_params_to_url(self, **query_params):
"""Appends query parameters onto the target URL.
Performs operations on the url attribute.
Returns the URL with query parameters attached to the end.
Expand All @@ -137,7 +142,7 @@ def add_query_params_to_url(self, **query_params):
:type query_params: Keyword arguments, required.
"""
for key, value in query_params.items():
self.url += (f"&{key}={value}")
self.url += (F"&{key}={value}")
return self.url

# Finalizes the url with the appropriate token - method does not determine which token to append
Expand Down Expand Up @@ -170,11 +175,20 @@ def make_iex_request(self):

# Step One
# Execution of class is split into two parts so that changes to the url can be made halfway through
def pre_execute(self, query_params):
self.add_query_params_to_url(self, query_params=None)
def pre_execute(self, **query_params):
self.add_query_params_to_url(self, query_params)

# Step Two
# Final execution step where token is added and request is made.
def execute(self):
self.append_token_to_url()
self.make_iex_request()
return self.make_iex_request()

#
# # Standard Usage of Class
# def iex_endpoint_request_dummy(section, symbol, endpoint, external=False):
# """Documentation"""
# instance = iexCommon(section, symbol, endpoint, external=external).pre_execute()
# # Here is where you would add extra things to the url by directly accessing instance.url
# return instance.execute()
#
8 changes: 5 additions & 3 deletions FinMesh/iex/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ def collection(collectionType, collectionName, external=False, vprint=False):

# Company
IEX_COMPANY_URL = prepend_iex_url('stock') + '{symbol}/company?'
def company(symbol, external=False, vprint=False):
def company(symbol, external=False, vprint=False, **query_params):
""":return: Company data such as website, address, and description for the requested company.
:param symbol: The ticker or symbol of the stock you would like to request.
:type symbol: string, required
"""
url = replace_url_var(IEX_COMPANY_URL, symbol=symbol)
return get_iex_json_request(url, external=external, vprint=vprint)
instance = iexCommon('stock', symbol, 'company', external=external)
return instance.execute()
# url = replace_url_var(IEX_COMPANY_URL, symbol=symbol)
# return get_iex_json_request(url, external=external, vprint=vprint)


# Delayed Quote
Expand Down
32 changes: 23 additions & 9 deletions build/lib/FinMesh/iex/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ class iexCommon():
:type external: Boolean or String. Default is False, insert token here to bypass using environment variables.
"""

def __init__(self, endpoint, symbol, external=False):
def __init__(self, section, symbol, endpoint, external=False):
self.url = f'iexapis.com/stable/{section}/{symbol}/{endpoint}?'
if external not False:
if not external == False:
self.token = external
self.parse_token_sandbox(self.token)
else:
self.sandbox_state = self.get_env_sandbox()
self.token = self.get_env_token()
if sandbox_state is True:
if self.sandbox_state is True:
self.url = 'https://sandbox.' + self.url
else:
self.url = 'https://cloud.' + self.url
Expand Down Expand Up @@ -121,14 +121,19 @@ def get_env_token(self):
Variable name is either 'IEX_SANDBOX_TOKEN' or 'IEX_TOKEN'
Whether the sandbox or production token is retrieved is determined by the environment SANDBOX state.
"""
if sandboxState:
if self.sandbox_state:
token = os.getenv('IEX_SANDBOX_TOKEN')
else:
token = os.getenv('IEX_TOKEN')
return token

def append_subdirectory_to_url(self, *subdir):
subdirectory_to_add = F"/{subdir}?"
self.url = self.url.replace("?", subdirectory_to_add)
return self.url

# Adds query paramters to the url
def add_query_params_to_url(self, **query_params):
def append_query_params_to_url(self, **query_params):
"""Appends query parameters onto the target URL.
Performs operations on the url attribute.
Returns the URL with query parameters attached to the end.
Expand All @@ -137,7 +142,7 @@ def add_query_params_to_url(self, **query_params):
:type query_params: Keyword arguments, required.
"""
for key, value in query_params.items():
self.url += (f"&{key}={value}")
self.url += (F"&{key}={value}")
return self.url

# Finalizes the url with the appropriate token - method does not determine which token to append
Expand Down Expand Up @@ -170,11 +175,20 @@ def make_iex_request(self):

# Step One
# Execution of class is split into two parts so that changes to the url can be made halfway through
def pre_execute(self, query_params):
self.add_query_params_to_url(self, query_params=None)
def pre_execute(self, **query_params):
self.add_query_params_to_url(self, query_params)

# Step Two
# Final execution step where token is added and request is made.
def execute(self):
self.append_token_to_url()
self.make_iex_request()
return self.make_iex_request()

#
# # Standard Usage of Class
# def iex_endpoint_request_dummy(section, symbol, endpoint, external=False):
# """Documentation"""
# instance = iexCommon(section, symbol, endpoint, external=external).pre_execute()
# # Here is where you would add extra things to the url by directly accessing instance.url
# return instance.execute()
#
10 changes: 6 additions & 4 deletions build/lib/FinMesh/iex/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def balance_sheet(symbol, external=False, vprint=False, **queries):
url += '?'
for key, value in queries.items():
url += (f"&{key}={value}")
return get_iex_json_request(url, external=external, external=external, vprint=vprint)
return get_iex_json_request(url, external=external, vprint=vprint)


# Batch Requests
Expand Down Expand Up @@ -70,14 +70,16 @@ def collection(collectionType, collectionName, external=False, vprint=False):

# Company
IEX_COMPANY_URL = prepend_iex_url('stock') + '{symbol}/company?'
def company(symbol, external=False, vprint=False):
def company(symbol, external=False, vprint=False, **query_params):
""":return: Company data such as website, address, and description for the requested company.
:param symbol: The ticker or symbol of the stock you would like to request.
:type symbol: string, required
"""
url = replace_url_var(IEX_COMPANY_URL, symbol=symbol)
return get_iex_json_request(url, external=external, vprint=vprint)
instance = iexCommon('stock', symbol, 'company', external=external)
return instance.execute()
# url = replace_url_var(IEX_COMPANY_URL, symbol=symbol)
# return get_iex_json_request(url, external=external, vprint=vprint)


# Delayed Quote
Expand Down
Binary file added dist/FinMesh-2.0.2-py3-none-any.whl
Binary file not shown.
Binary file added dist/FinMesh-2.0.2.tar.gz
Binary file not shown.
Binary file added dist/FinMesh-2.0.3-py3-none-any.whl
Binary file not shown.
Binary file added dist/FinMesh-2.0.3.tar.gz
Binary file not shown.
Binary file added dist/FinMesh-2.0.4-py3-none-any.whl
Binary file not shown.
Binary file added dist/FinMesh-2.0.4.tar.gz
Binary file not shown.
Binary file added dist/FinMesh-2.0.5-py3-none-any.whl
Binary file not shown.
Binary file added dist/FinMesh-2.0.5.tar.gz
Binary file not shown.
Binary file added dist/FinMesh-2.0.6-py3-none-any.whl
Binary file not shown.
Binary file added dist/FinMesh-2.0.6.tar.gz
Binary file not shown.
Binary file added dist/FinMesh-2.0.7-py3-none-any.whl
Binary file not shown.
Binary file added dist/FinMesh-2.0.7.tar.gz
Binary file not shown.
Binary file added dist/FinMesh-2.0.8-py3-none-any.whl
Binary file not shown.
Binary file added dist/FinMesh-2.0.8.tar.gz
Binary file not shown.
Binary file added dist/FinMesh-2.0.9-py3-none-any.whl
Binary file not shown.
Binary file added dist/FinMesh-2.0.9.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setuptools.setup(
name = "FinMesh",
version = "2.0.2",
version = "2.0.9",
author = "Michael and Josh Hartmann",
author_email = "[email protected]",
description = "A Python wrapper to bring together various financial APIs.",
Expand Down
2 changes: 1 addition & 1 deletion testupdate.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
echo Creating new distributions...
python3 setup.py sdist bdist_wheel
echo Uploading new version to Pypi...
twine upload --repository testpypi dist/*
twine upload --skip-existing --repository testpypi dist/*

echo Upgrading FinMesh...
pip install --force-reinstall --index-url https://test.pypi.org/simple/ FinMesh
Expand Down

0 comments on commit 6face0d

Please sign in to comment.