Skip to content

Commit b8b32f7

Browse files
committed
Fix some logging code failed to work and refine log format
As is in issue #18, this commit fixes some logging code failed to work. That's because `Logger.<debug|info|warning|error>()` has a similar but different parameter form from that of `print()`. The method of `Logger` needs the positional arguments other than the first one to be contents of the `%`-like templates in the first `str` argument, but that's very different from `print()`'s behavior. And this commit refines format of some logging code.
1 parent f8b6c17 commit b8b32f7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

auto_comment_plus.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def ordinary(N, opts=None):
246246
url2 = "https://club.jd.com/myJdcomments/saveProductComment.action"
247247
opts['logger'].debug('URL: %s', url2)
248248
xing, Str = generation(oname, opts=opts)
249-
opts['logger'].info(f'\t\t评价内容,星级{xing}:', Str)
249+
opts['logger'].info(f'\t\t评价内容,星级{xing}:' + Str)
250250
data2 = {
251251
'orderId': oid,
252252
'productId': pid, # 商品id
@@ -260,7 +260,8 @@ def ordinary(N, opts=None):
260260
opts['logger'].debug('Sending comment request')
261261
pj2 = requests.post(url2, headers=headers, data=data2)
262262
else:
263-
opts['logger'].debug('Skipped sending comment request in dry run')
263+
opts['logger'].debug(
264+
'Skipped sending comment request in dry run')
264265
opts['logger'].debug('Sleep time (s): %.1f', ORDINARY_SLEEP_SEC)
265266
time.sleep(ORDINARY_SLEEP_SEC)
266267
idx += 1
@@ -519,7 +520,7 @@ def Service_rating(N, opts=None):
519520
pj1 = requests.post(url1, headers=headers, data=data1)
520521
else:
521522
opts['logger'].debug('Skipped sending comment request in dry run')
522-
opts['logger'].info("\t\t", pj1.text)
523+
opts['logger'].info("\t\t " + pj1.text)
523524
opts['logger'].debug('Sleep time (s): %.1f', SERVICE_RATING_SLEEP_SEC)
524525
time.sleep(SERVICE_RATING_SLEEP_SEC)
525526
N['服务评价'] -= 1
@@ -530,8 +531,8 @@ def No(opts=None):
530531
opts = opts or {}
531532
opts['logger'].info('')
532533
N = all_evaluate(opts)
533-
for i in N:
534-
opts['logger'].info('{} {}----'.format(i, N[i]))
534+
s = '----'.join(['{} {}'.format(i, N[i]) for i in N])
535+
opts['logger'].info(s)
535536
opts['logger'].info('')
536537
return N
537538

0 commit comments

Comments
 (0)