diff --git a/poems/catalog.py b/poems/catalog.py index 5fc2d14..116b177 100644 --- a/poems/catalog.py +++ b/poems/catalog.py @@ -101,7 +101,7 @@ def apply_context(self, context: Context, forced=[], verbose=False): if keyword == context_dict[category]: if keyword in forced: if verbose: - print(f"FORCING CONTEXT: {category}='{keyword}'") + logger.info(f"FORCING CONTEXT: {category}='{keyword}'") multiplier = 1e18 else: multiplier = weight @@ -155,7 +155,7 @@ def apply_history(self, history: DataFrame, cooldown: int = 30 * 86400, manage_a treated_authors.append(entry.author) if verbose: - print(f"Dropped authors {dropped_authors}.") + logger.info(f"Dropped authors {dropped_authors}.") self.df.loc[indices_to_drop, "likelihood"] = 0 diff --git a/poems/curator.py b/poems/curator.py index b69bf5e..17bded4 100644 --- a/poems/curator.py +++ b/poems/curator.py @@ -6,6 +6,9 @@ from .data import authors import pandas as pd +import logging + +logger = logging.getLogger("poems") here, this_file = os.path.split(__file__) @@ -76,11 +79,11 @@ def get_poem( author_summary = pd.DataFrame(author_summary_entries).T.sort_values(["probability"], ascending=[False]) - print(f"choosing from {len(self.catalog.df)} poems; the most likely are:") + logger.info(f"choosing from {len(self.catalog.df)} poems; the most likely are:") print(catalog_summary.iloc[:20].to_string()) print() - print(f"choosing from {len(author_summary)} authors; the most likely are:") + logger.info(f"choosing from {len(author_summary)} authors; the most likely are:") print(author_summary.iloc[:20].to_string()) print() @@ -88,7 +91,7 @@ def get_poem( chosen_author, chosen_title = self.catalog.df.loc[chosen_loc, ["author", "title"]] if verbose: - print(f"chose poem '{chosen_title}' by {chosen_author}") + logger.info(f"chose poem '{chosen_title}' by {chosen_author}") self.catalog.reset() diff --git a/poems/tests/test_curator.py b/poems/tests/test_curator.py index 97f0167..19b6328 100644 --- a/poems/tests/test_curator.py +++ b/poems/tests/test_curator.py @@ -1,7 +1,5 @@ from poems import Curator - - def test_curator(): curator = Curator() p = curator.get_poem(very_verbose=True) diff --git a/poems/utils.py b/poems/utils.py index 76aff11..d894ea1 100644 --- a/poems/utils.py +++ b/poems/utils.py @@ -69,11 +69,11 @@ def email_thread(username: str, content=content, recipient=recipient) a, b = recipient.split("@") - print(f"{datetime.now().isoformat()} | {a:>24} @ {b:<20}") + logger.info(f"Set email to {a:>24} @ {b:<20}") done = True except Exception as error: logger.warning(error) - print(f"Encountered error for recipient {recipient}. Trying again in 60 seconds...") + logger.warning(f"Encountered error for recipient {recipient}. Trying again in 60 seconds...") fails += 1 time.sleep(60) @@ -102,7 +102,7 @@ def write_to_repo(repo, items, branch="master", verbose=False): blob = repo.create_git_blob(content, "utf-8") elements.append(gh.InputGitTreeElement(path=filename, mode="100644", type="blob", sha=blob.sha)) - if verbose: print(f"writing to {filename}") + if verbose: logger.info(f"writing to {filename}") head_sha = repo.get_branch(branch).commit.sha base_tree = repo.get_git_tree(sha=head_sha) diff --git a/scripts/send-poem.py b/scripts/send-poem.py index 303a5af..8f45755 100644 --- a/scripts/send-poem.py +++ b/scripts/send-poem.py @@ -32,7 +32,7 @@ when = ttime.time() if args.mode == "daily" else ttime.time() + random.uniform(low=0, high=365 * 86400) context = Context(timestamp=when) -print(f"using context {context.to_dict()}") +logger.info(f"using context {context.to_dict()}") curator.catalog.apply_context(context, forced=["holy_thursday", "good_friday", "holy_saturday", "easter_sunday", "christmas_eve", "christmas_day"]) curator.catalog.apply_history(history, verbose=True) @@ -57,7 +57,7 @@ wait_seconds = (start_time - now).seconds if wait_seconds < 600: - logger.info(f"Waiting {wait_seconds:.03f} seconds.") + logger.info(f"Waiting {int(wait_seconds)} seconds.") ttime.sleep(wait_seconds) now = Context.now() @@ -96,7 +96,7 @@ daily_poems[str(index)] = packet except Exception as e: - logger.warning(f"Could not find poem for entry {entry}") + logger.warning(f"Could not find poem for entry {entry.to_dict()}") utils.write_to_repo(repo, items={