@@ -414,34 +414,60 @@ def on_header_resized(self):
414
414
save_config (g .config , g .data_list , update_data = False )
415
415
416
416
def load_type_hints (self , row ):
417
- try :
418
- self .tableWidget .type_hints = []
419
- # 当前行feed路径数据
420
- current_row_feed = g .data_list [row ][6 ]
421
- logger .info (f'current_row_feed { current_row_feed } ' )
422
- # 读取qb feed json数据
423
- feed_uid = None
424
- with open (g .config ['feeds_json_path' ], 'r' , encoding = 'utf-8' ) as f :
425
- feeds_json = json .loads (f .read ())
426
- logger .info (f'feeds_json { feeds_json } ' )
427
- for x in feeds_json :
428
- if current_row_feed == feeds_json [x ]['url' ]:
429
- feed_uid = feeds_json [x ]['uid' ].replace ('-' , '' )[1 :- 1 ]
430
- logger .info (f'feed_uid { feed_uid } ' )
431
- break
432
- if feed_uid :
433
- # 读取rss feed的标题 写入 type_hints 列表
417
+ # 输入过程中实时过滤数据
418
+ self .tableWidget .type_hints = []
419
+ # 当前行feed路径数据
420
+ current_row_feed = g .data_list [row ][6 ]
421
+ logger .info (f'current_row_feed { current_row_feed } ' )
422
+
423
+ if g .config ['use_qb_api' ] == 1 and check_qb_port_open (g .config ['qb_api_ip' ], g .config ['qb_api_port' ]):
424
+ # 使用qb的api读取feed
425
+ try :
426
+ qb_client .auth_log_in (username = g .config ['qb_api_username' ], password = g .config ['qb_api_password' ])
427
+ self .text_browser .append ('通过api获取feed' )
428
+ rss_feeds = qb_client .rss_items (include_feed_data = True )
434
429
article_titles = []
435
- article_path = g .config ['rss_article_folder' ] + '/' + feed_uid + '.json'
436
- with open (article_path , 'r' , encoding = 'utf-8' ) as f :
437
- article = json .loads (f .read ())
438
- for x in article :
439
- article_titles .append (x ['title' ])
430
+ for x in rss_feeds :
431
+ if current_row_feed == rss_feeds [x ]['url' ]:
432
+ for article in rss_feeds [x ]['articles' ]:
433
+ article_titles .append (article ['title' ])
440
434
self .tableWidget .type_hints = article_titles
441
435
logger .info (self .tableWidget .type_hints )
442
436
return True
443
- except Exception as e :
444
- logger .info (f'exception { e } ' )
437
+
438
+ # except qbittorrentapi.LoginFailed as e:
439
+ # self.text_browser.append('api登录失败')
440
+ # self.text_browser.append(e)
441
+ except Exception as e :
442
+ logger .error (e )
443
+ self .text_browser .append ('通过api连接qb失败' )
444
+ self .text_browser .append (f'报错信息 { repr (e )} ' )
445
+ else :
446
+ # 读取本地feed文件
447
+ try :
448
+ # 读取qb feed json数据
449
+ feed_uid = None
450
+ with open (g .config ['feeds_json_path' ], 'r' , encoding = 'utf-8' ) as f :
451
+ feeds_json = json .loads (f .read ())
452
+ logger .info (f'feeds_json { feeds_json } ' )
453
+ for x in feeds_json :
454
+ if current_row_feed == feeds_json [x ]['url' ]:
455
+ feed_uid = feeds_json [x ]['uid' ].replace ('-' , '' )[1 :- 1 ]
456
+ logger .info (f'feed_uid { feed_uid } ' )
457
+ break
458
+ if feed_uid :
459
+ # 读取rss feed的标题 写入 type_hints 列表
460
+ article_titles = []
461
+ article_path = g .config ['rss_article_folder' ] + '/' + feed_uid + '.json'
462
+ with open (article_path , 'r' , encoding = 'utf-8' ) as f :
463
+ article = json .loads (f .read ())
464
+ for x in article :
465
+ article_titles .append (x ['title' ])
466
+ self .tableWidget .type_hints = article_titles
467
+ logger .info (self .tableWidget .type_hints )
468
+ return True
469
+ except Exception as e :
470
+ logger .info (f'exception { e } ' )
445
471
self .text_browser .setText ('没找到RSS数据呀' )
446
472
447
473
def do_search (self ):
0 commit comments