fixes for json serialize bug

This commit is contained in:
Mikayla Dobson
2023-01-08 11:20:57 -06:00
parent 8f2d9faf1e
commit b7648dc4af
3 changed files with 20 additions and 26 deletions

View File

@@ -25,14 +25,14 @@ class Config:
self.set_pg_config()
self.output_formatting()
with open("./config.json", "w") as outfile:
json.dump(self.__encode(), outfile)
json.dump(self.__dict__, outfile)
return self
else:
self.receive_data_path()
self.set_pg_config()
self.output_formatting()
with open("./config.json", "w") as outfile:
json.dump(self.__encode(), outfile)
json.dump(self.__dict__, outfile)
return self
# if a config file already exists, offer to use it instead
@@ -42,9 +42,9 @@ class Config:
if response_for_prev_config == "y":
with open("./config.json", "r") as infile:
config_data = json.load(infile)
config_data: Config = json.load(infile)
return Config(config_data)
return config_data
elif response_for_prev_config == "n":
return None
else:
@@ -62,12 +62,6 @@ class Config:
print("Got it!")
self.data_path = data_path
def get_data_path(self):
return self.data_path
def set_data_path(self, value):
self.data_path = value
def set_pg_config(self):
"""Determine if data should be associated with a PostgreSQL instance, and, if so, record the required connection info"""
elect_for_pg = input("Connect this program to a PostgreSQL instance? y/n ").lower()
@@ -117,7 +111,4 @@ class Config:
self.sort_by_match_strength = False
else:
print("Invalid response.")
self.output_formatting()
def __encode(self):
return json.dumps(self, default=lambda x: x.__dict__)
self.output_formatting()