PyPtt 1.1.2.dev95668__tar.gz → 1.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PKG-INFO +2 -2
  2. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/PTT.py +80 -38
  3. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/__init__.py +3 -4
  4. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_call_status.py +7 -8
  5. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_change_pw.py +3 -6
  6. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_comment.py +21 -24
  7. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_del_post.py +8 -8
  8. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_get_board_info.py +11 -5
  9. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_get_board_list.py +4 -4
  10. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_get_bottom_post_list.py +11 -9
  11. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_get_favourite_board.py +4 -3
  12. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_get_newest_index.py +12 -17
  13. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_get_post.py +36 -35
  14. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_get_post_index.py +4 -8
  15. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_get_time.py +2 -3
  16. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_get_user.py +14 -16
  17. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_give_money.py +9 -0
  18. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_has_new_mail.py +2 -3
  19. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_loginout.py +14 -15
  20. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_mail.py +9 -17
  21. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_mark_post.py +3 -4
  22. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_post.py +5 -6
  23. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_reply_post.py +14 -15
  24. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_search_user.py +3 -2
  25. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_util.py +20 -26
  26. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/check_value.py +3 -6
  27. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/config.py +2 -3
  28. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/connect_core.py +39 -49
  29. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/data_type.py +3 -3
  30. PyPtt-1.2.1/PyPtt/i18n.py +58 -0
  31. PyPtt-1.2.1/PyPtt/lang/en_US.yaml +116 -0
  32. PyPtt-1.2.1/PyPtt/lang/zh_TW.yaml +116 -0
  33. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/lib_util.py +7 -11
  34. PyPtt-1.2.1/PyPtt/log.py +132 -0
  35. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/screens.py +9 -6
  36. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/service.py +16 -12
  37. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt.egg-info/PKG-INFO +2 -2
  38. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt.egg-info/SOURCES.txt +4 -1
  39. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt.egg-info/requires.txt +1 -1
  40. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/setup.py +3 -4
  41. PyPtt-1.1.2.dev95668/PyPtt/i18n.py +0 -1438
  42. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/LICENSE +0 -0
  43. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/MANIFEST.in +0 -0
  44. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_bucket.py +0 -0
  45. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/_api_set_board_title.py +0 -0
  46. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/command.py +0 -0
  47. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt/exceptions.py +0 -0
  48. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt.egg-info/dependency_links.txt +0 -0
  49. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/PyPtt.egg-info/top_level.txt +0 -0
  50. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/README.md +0 -0
  51. {PyPtt-1.1.2.dev95668 → PyPtt-1.2.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyPtt
3
- Version: 1.1.2.dev95668
3
+ Version: 1.2.1
4
4
  Summary: PyPtt
5
5
  Home-page: https://pyptt.cc/
6
6
  Author: CodingMan
@@ -27,9 +27,9 @@ License-File: LICENSE
27
27
  Requires-Dist: progressbar2
28
28
  Requires-Dist: websockets
29
29
  Requires-Dist: uao
30
- Requires-Dist: SingleLog
31
30
  Requires-Dist: requests
32
31
  Requires-Dist: AutoStrEnum
32
+ Requires-Dist: PyYAML
33
33
 
34
34
  ![](https://raw.githubusercontent.com/PttCodingMan/PyPtt/master/logo/facebook_cover_photo_2.png)
35
35
  # PyPtt
@@ -4,8 +4,6 @@ import functools
4
4
  import threading
5
5
  from typing import Dict, Tuple, Callable, List, Optional, Any
6
6
 
7
- from SingleLog import LogLevel, DefaultLogger
8
-
9
7
  from . import __version__
10
8
  from . import _api_bucket
11
9
  from . import _api_change_pw
@@ -33,15 +31,11 @@ from . import connect_core
33
31
  from . import data_type
34
32
  from . import i18n
35
33
  from . import lib_util
34
+ from . import log
36
35
 
37
36
 
38
37
  class API:
39
- def __init__(self, language: data_type.Language = data_type.Language.MANDARIN, log_level: LogLevel = LogLevel.INFO,
40
- screen_timeout: int = 3.0, screen_long_timeout: int = 10.0, screen_post_timeout: int = 60.0,
41
- connect_mode: data_type.ConnectMode = data_type.ConnectMode.WEBSOCKETS, port: int = 23,
42
- logger_callback: Optional[Callable] = None, host=data_type.HOST.PTT1,
43
- check_update: bool = True) -> None:
44
-
38
+ def __init__(self, **kwargs):
45
39
  """
46
40
 
47
41
  初始化 PyPtt。
@@ -69,26 +63,44 @@ class API:
69
63
  參考: :ref:`language`、LogLevel_、:ref:`connect-mode`、:ref:`host`
70
64
 
71
65
  .. _LogLevel: https://github.com/PttCodingMan/SingleLog/blob/d7c19a1b848dfb1c9df8201f13def9a31afd035c/SingleLog/SingleLog.py#L22
72
- """
73
66
 
74
- self.logger = None
67
+ 英文顯示範例::
68
+
69
+ import PyPtt
70
+
71
+ ptt_bot = PyPtt.API(
72
+ language=PyPtt.Language.ENGLISH)
73
+
74
+ 除錯範例::
75
+
76
+ import PyPtt
77
+
78
+ ptt_bot = PyPtt.API(
79
+ log_level=PyPtt.LogLevel.DEBUG)
75
80
 
76
- if not isinstance(log_level, LogLevel):
77
- raise TypeError('[PyPtt] log_level must be LogLevel')
78
81
 
79
- if logger_callback is not None and not callable(logger_callback):
80
- raise TypeError('[PyPtt] logger_callback must be callable')
82
+ """
83
+
84
+ log_level = kwargs.get('log_level', log.INFO)
85
+ if not isinstance(log_level, log.LogLv):
86
+ raise TypeError('[PyPtt] log_level must be log.Level')
81
87
 
82
- self.logger = DefaultLogger('PyPtt', log_level, handler=logger_callback, **config.LOGGER_CONFIG)
88
+ logger_callback = kwargs.get('logger_callback', None)
89
+ log.init(log_level, logger_callback=logger_callback)
83
90
 
84
- if not isinstance(language, data_type.Language):
91
+ language = kwargs.get('language', data_type.Language.MANDARIN)
92
+ if not isinstance(language, str):
93
+ raise TypeError('[PyPtt] language must be PyPtt.Language')
94
+ if language not in i18n.locale_pool:
85
95
  raise TypeError('[PyPtt] language must be PyPtt.Language')
86
96
 
87
97
  self.config = config.Config()
88
98
  self.config.log_level = log_level
89
99
 
90
100
  self.config.language = language
91
- i18n.load(self.config.language)
101
+
102
+ print('language', self.config.language)
103
+ i18n.init(self.config.language)
92
104
 
93
105
  self.is_mailbox_full: bool = False
94
106
  self.is_registered_user: bool = False
@@ -98,9 +110,15 @@ class API:
98
110
  self._ptt_pw: str = ''
99
111
  self._is_login: bool = False
100
112
 
113
+ host = kwargs.get('host', data_type.HOST.PTT1)
114
+ screen_timeout = kwargs.get('screen_timeout', 3.0)
115
+ screen_long_timeout = kwargs.get('screen_long_timeout', 10.0)
116
+ screen_post_timeout = kwargs.get('screen_post_timeout', 60.0)
117
+
101
118
  check_value.check_type(host, (data_type.HOST, str), 'host')
102
119
  check_value.check_type(screen_timeout, float, 'screen_timeout')
103
120
  check_value.check_type(screen_long_timeout, float, 'screen_long_timeout')
121
+ check_value.check_type(screen_post_timeout, float, 'screen_post_timeout')
104
122
 
105
123
  if screen_timeout != 0:
106
124
  self.config.screen_timeout = screen_timeout
@@ -112,10 +130,14 @@ class API:
112
130
  self.config.host = host
113
131
  self.host = host
114
132
 
133
+ port = kwargs.get('port', 23)
134
+
115
135
  check_value.check_type(port, int, 'port')
116
136
  check_value.check_range(port, 1, 65535 - 1, 'port')
117
137
  self.config.port = port
118
138
 
139
+ connect_mode = kwargs.get('connect_mode', data_type.ConnectMode.WEBSOCKETS)
140
+
119
141
  check_value.check_type(connect_mode, data_type.ConnectMode, 'connect_mode')
120
142
  if host in [data_type.HOST.PTT1, data_type.HOST.PTT2] and connect_mode is data_type.ConnectMode.TELNET:
121
143
  raise ValueError('[PyPtt] TELNET is not available on PTT1 and PTT2')
@@ -129,47 +151,53 @@ class API:
129
151
  self._board_info_list = dict()
130
152
  self._newest_index_data = data_type.TimedDict(timeout=2)
131
153
 
132
- self.logger.debug('ThreadID', self._thread_id)
154
+ log.logger.debug('thread_id', self._thread_id)
133
155
 
134
- self.logger.info(i18n.welcome)
156
+ log.logger.info(
157
+ i18n.replace(i18n.welcome, __version__))
135
158
 
136
- self.logger.info('PyPtt', i18n.init)
159
+ log.logger.info('PyPtt', i18n.initialization)
137
160
 
138
161
  if self.config.connect_mode == data_type.ConnectMode.TELNET:
139
- self.logger.info(i18n.set_connect_mode, i18n.connect_mode_TELNET)
162
+ log.logger.info(i18n.set_connect_mode, '...', i18n.connect_mode_TELNET)
140
163
  elif self.config.connect_mode == data_type.ConnectMode.WEBSOCKETS:
141
- self.logger.info(i18n.set_connect_mode, i18n.connect_mode_WEBSOCKET)
164
+ log.logger.info(i18n.set_connect_mode, '...', i18n.connect_mode_WEBSOCKET)
142
165
 
143
166
  if self.config.language == data_type.Language.MANDARIN:
144
- self.logger.info(i18n.set_up_lang_module, i18n.mandarin_module)
167
+ log.logger.info(i18n.set_up_lang_module, '...', i18n.mandarin_module)
145
168
  elif self.config.language == data_type.Language.ENGLISH:
146
- self.logger.info(i18n.set_up_lang_module, i18n.english_module)
169
+ log.logger.info(i18n.set_up_lang_module, '...', i18n.english_module)
147
170
 
148
171
  if self.config.host == data_type.HOST.PTT1:
149
- self.logger.info(i18n.set_connect_host, i18n.PTT)
172
+ log.logger.info(i18n.set_connect_host, '...', i18n.PTT)
150
173
  elif self.config.host == data_type.HOST.PTT2:
151
- self.logger.info(i18n.set_connect_host, i18n.PTT2)
174
+ log.logger.info(i18n.set_connect_host, '...', i18n.PTT2)
152
175
  elif self.config.host == data_type.HOST.LOCALHOST:
153
- self.logger.info(i18n.set_connect_host, i18n.localhost)
176
+ log.logger.info(i18n.set_connect_host, '...', i18n.localhost)
154
177
  else:
155
- self.logger.info(i18n.set_connect_host, self.config.host)
178
+ log.logger.info(i18n.set_connect_host, '...', self.config.host)
179
+
180
+ log.logger.info('PyPtt', i18n.initialization, '...', i18n.done)
181
+
182
+ check_update = kwargs.get('check_update', True)
183
+ check_value.check_type(check_update, bool, 'check_update')
156
184
 
157
185
  if check_update:
158
186
  version_compare, remote_version = lib_util.sync_version()
159
187
 
160
188
  if version_compare is data_type.Compare.SMALLER:
161
- self.logger.info(i18n.current_version, __version__)
162
- self.logger.info(i18n.new_version, remote_version)
189
+ log.logger.info(i18n.current_version, __version__)
190
+ log.logger.info(i18n.new_version, remote_version)
163
191
  elif version_compare is data_type.Compare.BIGGER:
164
- self.logger.info(i18n.development_version, __version__)
192
+ log.logger.info(i18n.development_version, __version__)
165
193
  else:
166
- self.logger.info(i18n.latest_version, __version__)
194
+ log.logger.info(i18n.latest_version, __version__)
167
195
  else:
168
- self.logger.info(i18n.current_version, __version__)
196
+ log.logger.info(i18n.current_version, __version__)
169
197
 
170
198
  def __del__(self):
171
- if self.logger:
172
- self.logger.debug(i18n.goodbye)
199
+ if log.logger:
200
+ log.logger.debug(i18n.goodbye)
173
201
 
174
202
  def login(self, ptt_id: str, ptt_pw: str, kick_other_session: bool = False) -> None:
175
203
 
@@ -258,7 +286,7 @@ class API:
258
286
 
259
287
  def get_post(self, board: str, aid: Optional[str] = None, index: Optional[int] = None,
260
288
  search_type: Optional[data_type.SearchType] = None, search_condition: Optional[str] = None,
261
- search_list: Optional[List[str]] = None, query: bool = False) -> Dict:
289
+ search_list: Optional[List[tuple]] = None, query: bool = False) -> Dict:
262
290
  """
263
291
  取得文章。
264
292
 
@@ -266,8 +294,6 @@ class API:
266
294
  board (str): 看板名稱。
267
295
  aid (str): 文章編號。
268
296
  index: 文章編號。
269
- search_type (:ref:`search-type`): 搜尋類型。
270
- search_condition (str): 搜尋條件。
271
297
  search_list (List[str]): 搜尋清單。
272
298
  query (bool): 是否為查詢模式。
273
299
 
@@ -302,6 +328,22 @@ class API:
302
328
  finally:
303
329
  ptt_bot.logout()
304
330
 
331
+ 使用搜尋範例::
332
+
333
+ import PyPtt
334
+
335
+ ptt_bot = PyPtt.API()
336
+ try:
337
+ # .. login ..
338
+ post_info = ptt_bot.get_post(
339
+ 'Python',
340
+ index=1,
341
+ search_list=[(PyPtt.SearchType.KEYWORD, 'PyPtt')]
342
+ )
343
+ # .. do something ..
344
+ finally:
345
+ ptt_bot.logout()
346
+
305
347
  | 更多範例參考 :ref:`取得文章 <check_post_status>`
306
348
  | 參考 :ref:`取得最新文章編號 <api-get-newest-index>`
307
349
  """
@@ -1,12 +1,11 @@
1
- __version__ = '1.1.2.dev95668'
2
-
3
- from SingleLog import LogLevel
1
+ __version__ = '1.2.1'
4
2
 
5
3
  from .PTT import API
6
4
  from .data_type import *
7
5
  from .exceptions import *
6
+ from .log import LogLevel
8
7
  from .service import Service
9
8
 
10
9
  LOG_LEVEL = LogLevel
11
10
 
12
- _main_version = '1.1'
11
+ _main_version = '1.2'
@@ -1,9 +1,8 @@
1
- from SingleLog import LogLevel
2
-
3
1
  from . import command
4
2
  from . import connect_core
5
3
  from . import data_type
6
4
  from . import exceptions
5
+ from . import log
7
6
  from . import screens
8
7
 
9
8
 
@@ -19,12 +18,12 @@ def get_call_status(api) -> None:
19
18
  cmd = ''.join(cmd_list)
20
19
 
21
20
  target_list = [
22
- connect_core.TargetUnit('[呼叫器]打開', log_level=LogLevel.DEBUG, break_detect=True),
23
- connect_core.TargetUnit('[呼叫器]拔掉', log_level=LogLevel.DEBUG, break_detect=True),
24
- connect_core.TargetUnit('[呼叫器]防水', log_level=LogLevel.DEBUG, break_detect=True),
25
- connect_core.TargetUnit('[呼叫器]好友', log_level=LogLevel.DEBUG, break_detect=True),
26
- connect_core.TargetUnit('[呼叫器]關閉', log_level=LogLevel.DEBUG, break_detect=True),
27
- connect_core.TargetUnit('★', log_level=LogLevel.DEBUG, response=cmd),
21
+ connect_core.TargetUnit('[呼叫器]打開', log_level=log.DEBUG, break_detect=True),
22
+ connect_core.TargetUnit('[呼叫器]拔掉', log_level=log.DEBUG, break_detect=True),
23
+ connect_core.TargetUnit('[呼叫器]防水', log_level=log.DEBUG, break_detect=True),
24
+ connect_core.TargetUnit('[呼叫器]好友', log_level=log.DEBUG, break_detect=True),
25
+ connect_core.TargetUnit('[呼叫器]關閉', log_level=log.DEBUG, break_detect=True),
26
+ connect_core.TargetUnit('★', log_level=log.DEBUG, response=cmd),
28
27
  ]
29
28
 
30
29
  for i in range(2):
@@ -1,20 +1,17 @@
1
- from SingleLog import DefaultLogger
2
-
3
1
  from . import command, _api_util
4
2
  from . import connect_core
5
3
  from . import exceptions
6
4
  from . import i18n
5
+ from . import log
7
6
 
8
7
 
9
8
  def change_pw(api, new_password: str) -> None:
10
9
  _api_util.one_thread(api)
11
10
 
12
- logger = DefaultLogger('api', api.config.log_level)
13
-
14
11
  if not api._is_login:
15
12
  raise exceptions.RequireLogin(i18n.require_login)
16
13
 
17
- logger.info(i18n.change_pw)
14
+ log.logger.info(i18n.change_pw)
18
15
 
19
16
  new_password = new_password[:8]
20
17
 
@@ -48,4 +45,4 @@ def change_pw(api, new_password: str) -> None:
48
45
 
49
46
  api._ptt_pw = new_password
50
47
 
51
- logger.info(i18n.success)
48
+ log.logger.info(i18n.change_pw, '...', i18n.success)
@@ -1,8 +1,6 @@
1
1
  import collections
2
2
  import time
3
3
 
4
- from SingleLog import LogLevel
5
-
6
4
  from . import _api_util
7
5
  from . import check_value
8
6
  from . import command
@@ -11,6 +9,7 @@ from . import data_type
11
9
  from . import exceptions
12
10
  from . import i18n
13
11
  from . import lib_util
12
+ from . import log
14
13
  from . import screens
15
14
 
16
15
  comment_option = [
@@ -27,7 +26,6 @@ def _comment(api,
27
26
  push_content: str,
28
27
  post_aid: str,
29
28
  post_index: int) -> None:
30
-
31
29
  _api_util.goto_board(api, board)
32
30
 
33
31
  cmd_list = []
@@ -45,16 +43,16 @@ def _comment(api,
45
43
  cmd = ''.join(cmd_list)
46
44
 
47
45
  target_list = [
48
- connect_core.TargetUnit('您覺得這篇', log_level=LogLevel.DEBUG, break_detect=True),
49
- connect_core.TargetUnit(f'→ {api.ptt_id}: ', log_level=LogLevel.DEBUG, break_detect=True),
50
- connect_core.TargetUnit('加註方式', log_level=LogLevel.DEBUG, break_detect=True),
51
- connect_core.TargetUnit('禁止快速連續推文', log_level=LogLevel.INFO, break_detect=True,
46
+ connect_core.TargetUnit('您覺得這篇', log_level=log.DEBUG, break_detect=True),
47
+ connect_core.TargetUnit(f'→ {api.ptt_id}: ', log_level=log.DEBUG, break_detect=True),
48
+ connect_core.TargetUnit('加註方式', log_level=log.DEBUG, break_detect=True),
49
+ connect_core.TargetUnit('禁止快速連續推文', log_level=log.INFO, break_detect=True,
52
50
  exceptions_=exceptions.NoFastComment()),
53
- connect_core.TargetUnit('禁止短時間內大量推文', log_level=LogLevel.INFO, break_detect=True,
51
+ connect_core.TargetUnit('禁止短時間內大量推文', log_level=log.INFO, break_detect=True,
54
52
  exceptions_=exceptions.NoFastComment()),
55
- connect_core.TargetUnit('使用者不可發言', log_level=LogLevel.INFO, break_detect=True,
53
+ connect_core.TargetUnit('使用者不可發言', log_level=log.INFO, break_detect=True,
56
54
  exceptions_=exceptions.NoPermission(i18n.no_permission)),
57
- connect_core.TargetUnit('◆ 抱歉, 禁止推薦', log_level=LogLevel.INFO, break_detect=True,
55
+ connect_core.TargetUnit('◆ 抱歉, 禁止推薦', log_level=log.INFO, break_detect=True,
58
56
  exceptions_=exceptions.CantComment()),
59
57
  ]
60
58
 
@@ -65,7 +63,7 @@ def _comment(api,
65
63
  if index == -1:
66
64
  raise exceptions.UnknownError('unknown error in comment')
67
65
 
68
- api.logger.info(i18n.has_comment_permission)
66
+ log.logger.debug(i18n.has_comment_permission)
69
67
 
70
68
  cmd_list = []
71
69
 
@@ -73,7 +71,7 @@ def _comment(api,
73
71
  push_option_line = api.connect_core.get_screen_queue()[-1]
74
72
  push_option_line = push_option_line.split('\n')[-1]
75
73
 
76
- api.logger.debug('comment option line', push_option_line)
74
+ log.logger.debug('comment option line', push_option_line)
77
75
 
78
76
  available_push_type = collections.defaultdict(lambda: False)
79
77
  first_available_push_type = None
@@ -96,7 +94,7 @@ def _comment(api,
96
94
  if first_available_push_type is None:
97
95
  first_available_push_type = data_type.CommentType.BOO
98
96
 
99
- api.logger.debug('available_push_type', available_push_type)
97
+ log.logger.debug('available_push_type', available_push_type)
100
98
 
101
99
  if available_push_type[push_type] is False:
102
100
  if first_available_push_type:
@@ -113,7 +111,7 @@ def _comment(api,
113
111
  cmd = ''.join(cmd_list)
114
112
 
115
113
  target_list = [
116
- connect_core.TargetUnit(screens.Target.InBoard, log_level=LogLevel.DEBUG, break_detect=True),
114
+ connect_core.TargetUnit(screens.Target.InBoard, log_level=log.DEBUG, break_detect=True),
117
115
  ]
118
116
 
119
117
  api.connect_core.send(
@@ -123,7 +121,6 @@ def _comment(api,
123
121
 
124
122
  def comment(api, board: str, push_type: data_type.CommentType, push_content: str, post_aid: str,
125
123
  post_index: int) -> None:
126
-
127
124
  if not api.is_registered_user:
128
125
  raise exceptions.UnregisteredUser(lib_util.get_current_func_name())
129
126
 
@@ -160,20 +157,20 @@ def comment(api, board: str, push_type: data_type.CommentType, push_content: str
160
157
  board_info = api._board_info_list[board.lower()]
161
158
 
162
159
  if board_info[data_type.BoardField.is_comment_record_ip]:
163
- api.logger.debug(i18n.record_ip)
160
+ log.logger.debug(i18n.record_ip)
164
161
  if board_info[data_type.BoardField.is_comment_aligned]:
165
- api.logger.debug(i18n.push_aligned)
162
+ log.logger.debug(i18n.push_aligned)
166
163
  max_push_length = 32
167
164
  else:
168
- api.logger.debug(i18n.not_push_aligned)
165
+ log.logger.debug(i18n.not_push_aligned)
169
166
  max_push_length = 43 - len(api.ptt_id)
170
167
  else:
171
- api.logger.debug(i18n.not_record_ip)
168
+ log.logger.debug(i18n.not_record_ip)
172
169
  if board_info[data_type.BoardField.is_comment_aligned]:
173
- api.logger.debug(i18n.push_aligned)
170
+ log.logger.debug(i18n.push_aligned)
174
171
  max_push_length = 46
175
172
  else:
176
- api.logger.debug(i18n.not_push_aligned)
173
+ log.logger.debug(i18n.not_push_aligned)
177
174
  max_push_length = 58 - len(api.ptt_id)
178
175
 
179
176
  push_content = push_content.strip()
@@ -200,7 +197,7 @@ def comment(api, board: str, push_type: data_type.CommentType, push_content: str
200
197
 
201
198
  for comment in push_list:
202
199
 
203
- api.logger.info(i18n.comment)
200
+ log.logger.info(i18n.comment)
204
201
 
205
202
  for _ in range(2):
206
203
  try:
@@ -208,7 +205,7 @@ def comment(api, board: str, push_type: data_type.CommentType, push_content: str
208
205
  break
209
206
  except exceptions.NoFastComment:
210
207
  # screens.show(api.config, api.connect_core.getScreenQueue())
211
- api.logger.info(i18n.wait_for_no_fast_comment)
208
+ log.logger.info(i18n.wait_for_no_fast_comment)
212
209
  time.sleep(5.2)
213
210
 
214
- api.logger.info(i18n.success)
211
+ log.logger.info(i18n.comment, '...', i18n.success)
@@ -10,6 +10,7 @@ from . import data_type
10
10
  from . import exceptions
11
11
  from . import i18n
12
12
  from . import lib_util
13
+ from . import log
13
14
  from . import screens
14
15
 
15
16
 
@@ -45,6 +46,8 @@ def del_post(api, board: str, post_aid: Optional[str] = None, post_index: int =
45
46
  post_index,
46
47
  newest_index)
47
48
 
49
+ log.logger.info(i18n.delete_post)
50
+
48
51
  board_info = _api_util.check_board(api, board)
49
52
 
50
53
  check_author = True
@@ -53,16 +56,17 @@ def del_post(api, board: str, post_aid: Optional[str] = None, post_index: int =
53
56
  check_author = False
54
57
  break
55
58
 
56
- api.logger.info(i18n.delete_post)
59
+ log.logger.info(i18n.delete_post)
57
60
 
58
61
  post_info = api.get_post(board, aid=post_aid, index=post_index, query=True)
59
62
  if post_info[data_type.PostField.post_status] != data_type.PostStatus.EXISTS:
60
63
  # delete success
61
- api.logger.info(i18n.success)
64
+ log.logger.info(i18n.success)
62
65
  return
63
66
 
64
67
  if check_author:
65
68
  if api.ptt_id.lower() != post_info[data_type.PostField.author].lower():
69
+ log.logger.info(i18n.delete_post, '...', i18n.fail)
66
70
  raise exceptions.NoPermission(i18n.no_permission)
67
71
 
68
72
  _api_util.goto_board(api, board)
@@ -97,13 +101,9 @@ def del_post(api, board: str, post_aid: Optional[str] = None, post_index: int =
97
101
  cmd,
98
102
  target_list)
99
103
 
100
- # last_screen = api.connect_core.get_screen_queue()[-1]
101
- # print(api.confirm)
102
- # print(last_screen)
103
- # print(index)
104
-
105
104
  if index == 1:
106
105
  if not api.confirm:
106
+ log.logger.info(i18n.delete_post, '...', i18n.fail)
107
107
  raise exceptions.NoPermission(i18n.no_permission)
108
108
 
109
- api.logger.info(i18n.success)
109
+ log.logger.info(i18n.delete_post, '...', i18n.success)
@@ -1,21 +1,19 @@
1
1
  import re
2
2
  from typing import Dict
3
3
 
4
- from SingleLog import DefaultLogger
5
- from SingleLog import LogLevel
6
-
7
4
  from . import _api_util
8
5
  from . import check_value
9
6
  from . import command
10
7
  from . import connect_core
11
8
  from . import exceptions
12
9
  from . import i18n
10
+ from . import log
13
11
  from . import screens
14
12
  from .data_type import BoardField
15
13
 
16
14
 
17
15
  def get_board_info(api, board: str, get_post_kind: bool, call_by_others: bool) -> Dict:
18
- logger = DefaultLogger('get_board_info', LogLevel.DEBUG if call_by_others else LogLevel.INFO)
16
+ logger = log.init(log.DEBUG if call_by_others else log.INFO)
19
17
 
20
18
  _api_util.one_thread(api)
21
19
 
@@ -24,6 +22,9 @@ def get_board_info(api, board: str, get_post_kind: bool, call_by_others: bool) -
24
22
 
25
23
  check_value.check_type(board, str, 'board')
26
24
 
25
+ logger.info(
26
+ i18n.replace(i18n.get_board_info, board))
27
+
27
28
  _api_util.goto_board(api, board, refresh=True)
28
29
 
29
30
  ori_screen = api.connect_core.get_screen_queue()[-1]
@@ -62,7 +63,7 @@ def get_board_info(api, board: str, get_post_kind: bool, call_by_others: bool) -
62
63
  logger.debug('人氣', online_user)
63
64
 
64
65
  target_list = [
65
- connect_core.TargetUnit('任意鍵繼續', log_level=LogLevel.DEBUG if call_by_others else LogLevel.INFO,
66
+ connect_core.TargetUnit('任意鍵繼續', log_level=log.DEBUG if call_by_others else log.INFO,
66
67
  break_detect=True),
67
68
  ]
68
69
 
@@ -229,6 +230,11 @@ def get_board_info(api, board: str, get_post_kind: bool, call_by_others: bool) -
229
230
  cmd,
230
231
  target_list)
231
232
 
233
+ logger.info(
234
+ i18n.replace(i18n.get_board_info, board),
235
+ '...', i18n.success
236
+ )
237
+
232
238
  return {
233
239
  BoardField.board: boardname,
234
240
  BoardField.online_user: online_user,
@@ -1,11 +1,11 @@
1
1
  import progressbar
2
- from SingleLog import LogLevel
3
2
 
4
3
  from . import _api_util
5
4
  from . import command
6
5
  from . import connect_core
7
6
  from . import exceptions
8
7
  from . import i18n
8
+ from . import log
9
9
  from . import screens
10
10
 
11
11
 
@@ -51,7 +51,7 @@ def get_board_list(api) -> list:
51
51
  # print(f'FrontPartList =>{FrontPartList}<=')
52
52
  max_no = int(front_part_list[0].rstrip(')'))
53
53
 
54
- if api.config.log_level == LogLevel.INFO:
54
+ if api.config.log_level == log.INFO:
55
55
  pb = progressbar.ProgressBar(
56
56
  max_value=max_no,
57
57
  redirect_stdout=True)
@@ -101,14 +101,14 @@ def get_board_list(api) -> list:
101
101
 
102
102
  board_list.append(board_name)
103
103
 
104
- if api.config.log_level == LogLevel.INFO:
104
+ if api.config.log_level == log.INFO:
105
105
  pb.update(no)
106
106
 
107
107
  if no >= max_no:
108
108
  break
109
109
  cmd = command.ctrl_f
110
110
 
111
- if api.config.log_level == LogLevel.INFO:
111
+ if api.config.log_level == log.INFO:
112
112
  pb.finish()
113
113
 
114
114
  return board_list
@@ -1,12 +1,11 @@
1
- from SingleLog import DefaultLogger
2
- from SingleLog import LogLevel
3
-
4
1
  from . import _api_util
5
2
  from . import check_value
6
3
  from . import command
7
4
  from . import connect_core
5
+ from . import data_type
8
6
  from . import exceptions
9
7
  from . import i18n
8
+ from . import log
10
9
  from . import screens
11
10
 
12
11
 
@@ -17,19 +16,20 @@ def get_bottom_post_list(api, board):
17
16
  raise exceptions.RequireLogin(i18n.require_login)
18
17
 
19
18
  check_value.check_type(board, str, 'board')
19
+
20
+ log.logger.info(i18n.catch_bottom_post)
21
+
20
22
  _api_util.check_board(api, board)
21
23
 
22
24
  _api_util.goto_board(api, board, end=True)
23
25
 
24
- logger = DefaultLogger('get_bottom_post_list')
25
-
26
26
  last_screen = api.connect_core.get_screen_queue()[-1]
27
27
 
28
28
  bottom_screen = [line for line in last_screen.split('\n') if '★' in line[:8]]
29
29
  bottom_length = len(bottom_screen)
30
30
 
31
31
  if bottom_length == 0:
32
- logger.info(i18n.catch_bottom_post_success)
32
+ log.logger.info(i18n.catch_bottom_post_success)
33
33
  return list()
34
34
 
35
35
  cmd_list = []
@@ -37,8 +37,10 @@ def get_bottom_post_list(api, board):
37
37
  cmd = ''.join(cmd_list)
38
38
 
39
39
  target_list = [
40
- connect_core.TargetUnit(screens.Target.QueryPost, log_level=LogLevel.DEBUG, break_detect=True, refresh=False),
41
- connect_core.TargetUnit(screens.Target.InBoard, log_level=LogLevel.DEBUG, break_detect=True),
40
+ connect_core.TargetUnit(
41
+ screens.Target.PTT1_QueryPost if api.config.host == data_type.HOST.PTT1 else screens.Target.PTT2_QueryPost,
42
+ log_level=log.DEBUG, break_detect=True, refresh=False),
43
+ connect_core.TargetUnit(screens.Target.InBoard, log_level=log.DEBUG, break_detect=True),
42
44
  connect_core.TargetUnit(screens.Target.MainMenu_Exiting, exceptions_=exceptions.NoSuchBoard(api.config, board)),
43
45
  ]
44
46
 
@@ -68,6 +70,6 @@ def get_bottom_post_list(api, board):
68
70
  current_post = api.get_post(board=board, aid=post_aid, query=True)
69
71
  result.append(current_post)
70
72
 
71
- logger.info(i18n.catch_bottom_post_success)
73
+ log.logger.info(i18n.catch_bottom_post, '...', i18n.success)
72
74
 
73
75
  return list(reversed(result))