You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
910 B
Python
33 lines
910 B
Python
# -*- coding: utf-8 -*-
|
|
# @Time : 2025/7/23 15:02
|
|
# @Author : zhaoxiangpeng
|
|
# @File : read_cfg.py
|
|
|
|
import json
|
|
|
|
|
|
def read_cfg(file):
|
|
with open(file, 'r', encoding='utf-8') as f:
|
|
while line := f.readline():
|
|
yield json.loads(line)
|
|
|
|
|
|
def format_cfg(cfg: dict):
|
|
list_selector = dict(list_s=cfg.pop('list_s'), label_s=cfg.pop('label_s', None), title_s=cfg.pop('title_s'),
|
|
datetime_s=cfg.pop('datetime_s'), news_link_s=cfg.pop('news_link_s'))
|
|
detail_selector = dict(content_s=cfg.pop('content_s'))
|
|
new_cfg = cfg.copy()
|
|
new_cfg['list_selector'] = list_selector
|
|
new_cfg['detail_selector'] = detail_selector
|
|
return new_cfg
|
|
|
|
|
|
def test_read_cfg():
|
|
for cfg in read_cfg('/scrapy-demo1/org_news/org_news/selector_cfg/library_selector.txt'):
|
|
print(cfg)
|
|
print(format_cfg(cfg))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
test_read_cfg()
|