feat: First version of the script
This commit is contained in:
47
main.py
Normal file
47
main.py
Normal file
@ -0,0 +1,47 @@
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
|
||||
|
||||
def create_pairs_dict(lst: list[str]) -> dict[str, str]:
|
||||
result = {}
|
||||
lst_len = len(lst)
|
||||
|
||||
if lst_len < 2:
|
||||
print("\033[1;31mList length should be at least 2!\033[0m")
|
||||
raise RuntimeError
|
||||
|
||||
for i in range(lst_len - 1):
|
||||
result[lst[i]] = lst[i+1]
|
||||
result[lst[lst_len-1]] = lst[0]
|
||||
|
||||
return result
|
||||
|
||||
|
||||
# Main
|
||||
input_file = "participants.json"
|
||||
output_file = "pairs.json"
|
||||
|
||||
|
||||
if os.path.isfile(input_file):
|
||||
print(f"\033[1;33mReading from {input_file}.\033[0m")
|
||||
with open(input_file, "r", encoding="utf-8") as f:
|
||||
participants_list = json.load(f)
|
||||
else:
|
||||
print("\033[1;31mNo input file found! Please create participants.json file.\033[0m")
|
||||
participants_list: list[str] = ["1", "2", "3", "4"]
|
||||
|
||||
shuffled_list = copy.copy(participants_list)
|
||||
random.shuffle(shuffled_list)
|
||||
pairs = create_pairs_dict(shuffled_list)
|
||||
|
||||
print(f"\033[1;33mWriting to {output_file}.\033[0m")
|
||||
with open(output_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(pairs, f, ensure_ascii=False, indent=4)
|
||||
|
||||
print("\033[1;32mFinished!\033[0m")
|
||||
|
||||
print("\nResults:")
|
||||
for giver, receiver in pairs.items():
|
||||
print(f"{giver} → {receiver}")
|
||||
Reference in New Issue
Block a user