Skip to content

Commit

Permalink
fix custom filepaths
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonDane committed Apr 16, 2024
1 parent 014b1f6 commit 11360a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
32 changes: 19 additions & 13 deletions fennel_invest_api/fennel.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,27 @@ def __init__(self, filename="fennel_credentials.pkl", path=None) -> None:
self.path = path
self._load_credentials()

def _verify_filepath(self):
def _load_credentials(self):
filename = self.filename
if self.path is not None:
self.filename = os.path.join(self.path, self.filename)
if not os.path.exists(self.filename):
filename = os.path.join(self.path, filename)
if not os.path.exists(self.path):
os.makedirs(self.path)

def _load_credentials(self):
self._verify_filepath()
if os.path.exists(self.filename):
with open(self.filename, "rb") as f:
if os.path.exists(filename):
with open(filename, "rb") as f:
credentials = pickle.load(f)
self.Bearer = credentials.get("Bearer")
self.Refresh = credentials.get("Refresh")
self.ID_Token = credentials.get("ID_Token")
self.client_id = credentials.get("client_id", self.client_id)

def _save_credentials(self):
self._verify_filepath()
with open(self.filename, "wb") as f:
filename = self.filename
if self.path is not None:
filename = os.path.join(self.path, filename)
if not os.path.exists(self.path):
os.makedirs(self.path)
with open(filename, "wb") as f:
pickle.dump(
{
"Bearer": self.Bearer,
Expand All @@ -63,9 +65,13 @@ def _save_credentials(self):
)

def _clear_credentials(self):
self._verify_filepath()
if os.path.exists(self.filename):
os.remove(self.filename)
filename = self.filename
if self.path is not None:
filename = os.path.join(self.path, filename)
if not os.path.exists(self.path):
os.makedirs(self.path)
if os.path.exists(filename):
os.remove(filename)
self.Bearer = None
self.Refresh = None
self.ID_Token = None
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="fennel_invest_api",
version="1.0.0",
version="1.0.1",
description="Unofficial Fennel.com Invest API written in Python Requests",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 11360a8

Please sign in to comment.