-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandom.py
140 lines (126 loc) · 5.7 KB
/
Random.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import random
# удаляем запись о выпавшей серии из list
# и презаписываем файл списка просмотренных эпизодов
def Remove_episode(episode):
__ep_index = spisok.index(episode)
del spisok[__ep_index]
with open('random_list.txt', 'w') as file:
file.write('\n'.join(spisok))
# добавляем выпавшую серию в список просмотренного
def Add_episode(episode):
watched_list = open('watched_list.txt', 'a')
if len(watched_spisok) == 0:
watched_list.write('%s' % episode)
print('Первая просмотренная серия!')
else:
watched_list.write('\n%s' % episode)
print('Новая серия добавлена в просмотренные')
watched_spisok.append(episode)
watched_list.close()
# сбрасываем список просмотренных серий
def Reset_list():
print('Непросмотренных серий не осталось')
print('Введите reset для сброса всего списка серий')
if input() == 'reset':
print('Вы уверены? Если да, то введите yes')
if input() == 'yes':
sorted_spisok = [] # избаляемся от повторяющихся записей
for episode in watched_spisok:
if episode not in sorted_spisok:
sorted_spisok.append(episode)
sorted_spisok.sort() #сортируем по возрастанию
with open('random_list.txt', 'w') as file:
file.write('\n'.join(sorted_spisok))
print('Готово! Список упешно сброшен')
f = open('watched_list.txt', 'w')
f.close()
# помечаем серию непросмотренной
def Return_episode(episode):
if episode in watched_spisok:
spisok.append(episode)
__ep_index = spisok.index(episode)
del spisok[__ep_index]
with open('random_list.txt', 'w') as file:
file.write('\n'.join(spisok))
else:
print('Серия не помечена как просмотренная')
with open('random_list.txt') as file:
spisok = [row.strip() for row in file] #открываем список всех серий и записываем его в spisok
with open('watched_list.txt') as file:
watched_spisok = [row.strip() for row in file] #записываем список просмотренных серий в watched_list
cleaned_spisok = []
for line in spisok:
if line in watched_spisok:
#cleaned_spisok.append(line)
Remove_episode(line)
#spisok.clear()
#spisok = cleaned_spisok
print ('episodes left ', len(spisok))
watched_spisok.sort()
# while True:
print('Введите команду "run" для выбора новой серии')
print('Используйте "add" чтобы пометить серию как просмотренную')
print('Команда "return" убирает пометку о просмторе с серии')
print('Для закрытия программы введите "stop"')
input_data = input()
# run выбирает случайную серию из списка и проверяет
# не находится ли она в списке просмотренного
def run():
flag = 0
if len(spisok) == 0:
Reset_list()
with open('random_list.txt') as file:
spisok = [row.strip() for row in file]
with open('watched_list.txt') as file:
watched_spisok = [row.strip() for row in file]
flag = 1
while flag == 0:
episode = random.choice(spisok)
ep_index = spisok.index(episode)
if episode not in watched_spisok:
print(episode)
Remove_episode(episode)
Add_episode(episode)
flag = 1
else:
Remove_episode(episode)
# add запрашивает номер серии, вносит ее в список просмотренных
# и удаляет из основного списка
def add():
flag_data = 1
while flag_data != 0:
print('Для выхода введите "0"')
print('Введите номер серии:')
episode = input()
if episode != '0':
if episode not in watched_spisok:
print('%s серия помечена как просмотренная' % episode)
Add_episode(episode)
Remove_episode(episode)
else:
print('Эта серия уже в списке просмотренных')
else:
flag_data = 0
# return удаляет серию из списка просмотренных
# и возвращает ее в список оставшихся серий
def remove():
flag_data = 1
while flag_data != 0:
print('Для выхода введите "0"')
print('Введите номер серии:')
episode = input()
if episode != '0':
print('%s серия убрана из просмотренных' % episode)
Return_episode(episode)
else:
flag_data = 0
# останавливает выполнение кода
# def stop():
# break
# все прочие команды вызывают сообщение о количестве
# оставшихся серий
def ep_left():
with open('random_list.txt') as file:
spisok = [row.strip() for row in file]
print('Осталось непросмотренных серий %s' % len(spisok))
print('Runned')