Skip to content

Commit

Permalink
Show exact effective timestamp used to determine winners
Browse files Browse the repository at this point in the history
  • Loading branch information
lukecyca committed Jan 5, 2025
1 parent edaf960 commit 8d32743
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions libs/discourse_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import logging
import pickle
from datetime import datetime
import zoneinfo

vancouver_timezone = zoneinfo.ZoneInfo("America/Vancouver")

from pydiscourse import DiscourseClient

Expand All @@ -23,7 +26,22 @@ def generate_post_winners(all_items: list) -> str:

post += "<h1>Raffle Results</h1>\n\n"

last_close_time = None

for item in all_items:

# Technically each poll could have a different close time.
# This handles that by printing it once at the beginning, and
# again each time we get to a new poll where it differs from the last.
if last_close_time != item["close_time"]:
ts = datetime.fromtimestamp(
item["close_time"], tz=vancouver_timezone)
post += "Raffle was closed at: {} ({})\n\n".format(
ts.isoformat(),
item["close_time"],
)
last_close_time = item["close_time"]

post += f"**{item['description']}**\n"

post += "\nWinners:\n"
Expand Down

0 comments on commit 8d32743

Please sign in to comment.