Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions spamdb/modules/puzzle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import random
from modules.env import env
import modules.util as util


def update_puzzle_colls() -> None:
args = env.args
db = env.db

if args.drop:
db.puzzle2_round.drop()

puzzles: list[PuzzleRound] = []

for uid in env.uids:
sample_puzzles = random.sample(env.puzzles, 10)
for i in range(10):
pid = f"{uid}:{sample_puzzles[i].get("_id")}"
puzzles.append(PuzzleRound(uid, pid))

if args.no_create:
return

util.bulk_write(db.puzzle2_round, puzzles)

class PuzzleRound:
def __init__(self, uid: str, pid: str):
self._id = pid
self.w = random.choice([True, False])
self.d = util.time_since_days_ago(10)
self.u = uid
2 changes: 2 additions & 0 deletions spamdb/spamdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def main():
import modules.blog as blog
import modules.cms as cms
import modules.feed as feed
import modules.puzzle as puzzle
import modules.game as game
import modules.team as team
import modules.tour as tour
Expand Down Expand Up @@ -57,6 +58,7 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
msg.update_msg_colls()
blog.update_blog_colls()
feed.update_feed_colls()
puzzle.update_puzzle_colls()
cms.update_cms_colls()
event.update_event_colls()
video.update_video_colls()
Expand Down