-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
93 lines (66 loc) · 2.81 KB
/
utils.py
File metadata and controls
93 lines (66 loc) · 2.81 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
import random
from dotenv import load_dotenv
from aiogram.dispatcher.filters.state import State, StatesGroup
from texts import quiz
load_dotenv()
# Хранилище для уже показанных фотографий
shown_photos = []
def get_random_photo() -> str:
photo_dirs = os.getenv('PHOTOS_COMPLIMENT_DIRECTORY')
if not os.path.exists(photo_dirs):
raise Exception('No photo directory')
list_photo = os.listdir(photo_dirs)
if not list_photo:
raise Exception('Photo folder is empty')
random_photo = random.choice(list_photo)
path_photo = os.path.join(photo_dirs, random_photo)
return path_photo
def get_random_photo_flirt() -> str:
photo_dirs = os.getenv('PHOTOS_FLIRT_DIRECTORY')
if not os.path.exists(photo_dirs):
raise Exception('No photo directory')
list_photo = os.listdir(photo_dirs)
if not list_photo:
raise Exception('Photo folder is empty')
random_photo = random.choice(list_photo)
path_photo = os.path.join(photo_dirs, random_photo)
return path_photo
def get_random_photo_girl() -> str:
global shown_photos
photo_dirs = os.getenv('PHOTOS_GIRL_DIRECTORY')
if not os.path.exists(photo_dirs):
raise Exception('No photo directory')
list_photo = os.listdir(photo_dirs)
if not list_photo:
raise Exception('Photo folder is empty')
# Если все фотографии показаны, сбросить список показанных фотографий
if len(shown_photos) == len(list_photo):
shown_photos = []
# Найти фотографию, которая еще не была показана
remaining_photos = [photo for photo in list_photo if photo not in shown_photos]
random_photo = random.choice(remaining_photos)
# Добавить выбранную фотографию в список показанных
shown_photos.append(random_photo)
path_photo = os.path.join(photo_dirs, random_photo)
return path_photo
def current_question(question_number: int) -> tuple[str, list, str]:
quiz_number = quiz.IT[question_number]
question_text = quiz_number.get("question")
list_answers = quiz_number.get("answers")
correct_answer = quiz_number.get("correct_answer")
return question_text, list_answers, correct_answer
class QuizState(StatesGroup):
start_quiz = State()
number_correct_answers = State()
'''def get_random_photo_girl() -> str:
photo_dirs = os.getenv('PHOTOS_GIRL_DIRECTORY')
if not os.path.exists(photo_dirs):
raise Exception('No photo directory')
list_photo = os.listdir(photo_dirs)
if not list_photo:
raise Exception('Photo folder is empty')
random_photo = random.choice(list_photo)
path_photo = os.path.join(photo_dirs, random_photo)
return path_photo
'''