-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
95 lines (74 loc) · 2.09 KB
/
test.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
import pickle, os
class User:
"""
User情報を保持するクラス
"""
def __init__(self, novel_title, novel):
self._userID = self._generate_user_id()
self._novel_title = novel_title
self._novel = novel
self._done = []
self._conversation = []
self._question = None
self._answer = None
self._preview = None
def fitch_next_candidate(self):
"""
次の会話文と、previewを返す
:return:
"""
return (self._novel.pop(0), self._novel[:4]) if len(self._novel) else (None, None)
def _generate_user_id(self):
"""
英数字から10桁のランダムな文字列を生成する。
:return:
"""
SEEDS = '1234567890abcdefghigklmopqrstuvwsxyzABCDEFGHIJKLMNOPQRSTUVWYZ'
rand = random.Random(datetime.datetime.now())
return ''.join([n for _ in range(10) for n in rand.choice(SEEDS)])
@property
def userID(self):
return self._userID
@property
def novel(self):
return self._novel
@property
def done(self):
return self._done.pop()
@property
def conversation(self):
return self._conversation
@property
def novel_title(self):
return self._novel_title
@property
def question(self):
return self._question
@property
def answer(self):
return self._answer
@property
def preview(self):
return self._preview
@novel.setter
def novel(self, value):
self._novel = value
@done.setter
def done(self, value):
self._done.append(value)
@conversation.setter
def conversation(self, value):
self._conversation.append(value)
@question.setter
def question(self, value):
self._question = value
@answer.setter
def answer(self, value):
self._answer = value
@preview.setter
def preview(self, value):
self._preview = value
file = os.path.join(os.curdir, 'temp', '9A81H2wyKK.pkl')
with open(file,'rb') as f:
user = pickle.load(f)
print(user.userID)