Skip to content

Commit

Permalink
fix timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Morris committed Apr 8, 2024
1 parent 13b7020 commit caa3185
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
20 changes: 11 additions & 9 deletions poems/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class Poem():
timestamp: int = None

@classmethod
def from_catalog(cls, author, title, context=None):
def from_catalog(cls, author, title, context=None, timestamp=None):
return cls(author=Author(**db[author]["metadata"]),
**db[author]["poems"][title], context=context)
**db[author]["poems"][title], context=context, timestamp=timestamp)

def __post_init__(self):

Expand Down Expand Up @@ -284,22 +284,24 @@ def get_poem(
forced_contexts=[],
verbose=True,
very_verbose=False,
**kwargs,
timestamp=None,
):

if timestamp is None:
timestamp = Context.now().timestamp

verbose = verbose or very_verbose
self.catalog = self.archive_poems.copy()

if context is None:
context = Context.now().to_dict()

self.when = ttime.time()
context = Context(timestamp=timestamp).to_dict()

if "timestamp" in context.keys():
self.when = context["timestamp"]
timestamp = context["timestamp"]

if author and title:
if title in db[author]["poems"].keys():
return Poem.from_catalog(author=author, title=title, context=context)
return Poem.from_catalog(author=author, title=title, context=context, timestamp=timestamp)
else:
raise PoemNotFoundError(f"There is no poem \"{title}\" by \"{author}\" in the database.")

Expand Down Expand Up @@ -402,7 +404,7 @@ def get_poem(
if verbose:
print(f"chose poem \"{chosen_title}\" by {chosen_author}")

poem = Poem.from_catalog(author=chosen_author, title=chosen_title, context=context)
poem = Poem.from_catalog(author=chosen_author, title=chosen_title, context=context, timestamp=timestamp)

now = datetime.now(tz=pytz.utc)

Expand Down
3 changes: 1 addition & 2 deletions scripts/send-poem.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,9 @@ def thread_process(poem, username, password, name, email, subject):
curator.history.drop(index=curator.history.iloc[-1].name, inplace=True)

daily_poems = {}

for index, entry in curator.history.iterrows():
try:
p = curator.get_poem(author=entry.author, title=entry.title, when=entry.timestamp, verbose=True)
p = curator.get_poem(author=entry.author, title=entry.title, timestamp=entry.timestamp, verbose=True)
daily_poems[str(index)] = {
"date": p.date,
"author": {
Expand Down

0 comments on commit caa3185

Please sign in to comment.