-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
37 lines (26 loc) · 1.04 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from fastapi import FastAPI
import json
import os
import random
import math
this_file_folder = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(this_file_folder, "words.txt"), "r") as input:
available_words = [word.replace("\n", "") for word in input.readlines()]
app = FastAPI()
@app.get("/{seed}/")
async def words(seed):
random.seed(seed)
selected_words = random.sample(available_words, k=25)
words_per_team_count = 5
blue_words = selected_words[:words_per_team_count]
red_words = selected_words[words_per_team_count : words_per_team_count * 2]
black_words = [selected_words[words_per_team_count * 2]]
white_words = selected_words[words_per_team_count * 2 + 1 :]
words = (
[{"name": word, "role": "blue"} for word in blue_words]
+ [{"name": word, "role": "red"} for word in red_words]
+ [{"name": word, "role": "black"} for word in black_words]
+ [{"name": word, "role": "white"} for word in white_words]
)
random.shuffle(words)
return {"words": words}