From 02fc7b47b6e1abfe5e6e5be4c6a53e958d97f968 Mon Sep 17 00:00:00 2001 From: Michael Antoun Date: Sat, 11 Nov 2023 19:12:22 -0800 Subject: [PATCH] added config parsing to decide email addresses and operation mode --- config.json | 2 +- document_analysis.py | 27 ++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/config.json b/config.json index 0a315c3..f40fb96 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,4 @@ { - "Emails": [], + "emails": ["aozalevsky@gmail.com", "steveurkel99@gmail.com"], "DEBUG": false } \ No newline at end of file diff --git a/document_analysis.py b/document_analysis.py index be85901..0326e24 100644 --- a/document_analysis.py +++ b/document_analysis.py @@ -1,3 +1,4 @@ +import json import re from VectorDatabase import Lantern, Publication @@ -18,13 +19,33 @@ class DocumentAnalyzer: aggregates the results, and reports the results to the spreadsheet """ + CONFIG_PATH = "./config.json" + def __init__(self): self.lantern = Lantern() self.sheets = SheetsApiClient() self.llm = LlmHandler() - self.email_addresses = [] - self.notification_via_email = True + self.email_addresses, self.notification_via_email = self.parse_config() + + @staticmethod + def parse_config(): + try: + with open(DocumentAnalyzer.CONFIG_PATH, 'r') as config_file: + config_data = json.load(config_file) + + # Extracting fields from the config_data + my_list = config_data.get('emails', []) # Default to an empty list if 'my_list' is not present + my_bool = config_data.get('DEBUG', False) # Default to False if 'my_bool' is not present + + return my_list, my_bool + + except FileNotFoundError: + print(f"Config file '{DocumentAnalyzer.CONFIG_PATH}' not found. Using defaults (no email addresses)") + return [], False + except json.JSONDecodeError as e: + print(f"Error decoding JSON in '{DocumentAnalyzer.CONFIG_PATH}': {e}") + return None, None def analyze_all_unread(self): """pulls all new files from Lantern database, evaluates them, and publishes results to google sheets @@ -162,7 +183,7 @@ def evaluate_queries(self, embedding, queries): def main(): document_analyzer = DocumentAnalyzer() - document_analyzer.analyze_all_unread() # analyzes all new files in lantern db + #document_analyzer.analyze_all_unread() # analyzes all new files in lantern db if __name__ == '__main__':