From 6608cf1c2bc5a77832748eacbe1c3a42b15547c7 Mon Sep 17 00:00:00 2001 From: hillerliao Date: Tue, 9 Aug 2022 18:20:57 +0800 Subject: [PATCH] lightly init --- .lightly/settings.toml | 6 ++++ main.py | 20 ++++++------- rsshub/spiders/bjnews/channel.py | 50 ++++++++++++++++---------------- 3 files changed, 41 insertions(+), 35 deletions(-) create mode 100644 .lightly/settings.toml diff --git a/.lightly/settings.toml b/.lightly/settings.toml new file mode 100644 index 0000000..1a9fa50 --- /dev/null +++ b/.lightly/settings.toml @@ -0,0 +1,6 @@ + +title = "lightly settings" + +ports = [] + +[languages] diff --git a/main.py b/main.py index dc02663..48a9731 100644 --- a/main.py +++ b/main.py @@ -1,10 +1,10 @@ -import os -from dotenv import load_dotenv - -dotenv_path = os.path.join(os.path.dirname(__file__), '.env') -if os.path.exists(dotenv_path): - load_dotenv(dotenv_path) - -from rsshub import create_app - -app = create_app('production') \ No newline at end of file +import os +from dotenv import load_dotenv + +dotenv_path = os.path.join(os.path.dirname(__file__), '.env') +if os.path.exists(dotenv_path): + load_dotenv(dotenv_path) + +from rsshub import create_app + +app = create_app('production') diff --git a/rsshub/spiders/bjnews/channel.py b/rsshub/spiders/bjnews/channel.py index b7a2b93..28ad3b0 100644 --- a/rsshub/spiders/bjnews/channel.py +++ b/rsshub/spiders/bjnews/channel.py @@ -1,25 +1,25 @@ -from rsshub.utils import fetch - -domain = 'http://www.bjnews.com.cn' - - -def parse(post): - item = {} - item['description'] = item['title'] = post.css('a::text').extract_first() - item['link'] = post.css('a::attr(href)').extract_first() - return item - - -def ctx(category=''): - r_url = f"{domain}/{category}" - tree = fetch(r_url) - html = tree.css('body') - posts = tree.css('.list-a').css('li') - channel_title = html.css('a.cur::text').extract_first().strip() - return { - 'title': f'{channel_title} - 新京报', - 'link': r_url, - 'description': f'新京报「{channel_title}」频道新闻', - 'author': 'hillerliao', - 'items': list(map(parse, posts)) - } \ No newline at end of file +from rsshub.utils import fetch + +domain = 'http://www.bjnews.com.cn' + + +def parse(post): + item = {} + item['description'] = item['title'] = post.css('a::text').extract_first() + item['link'] = post.css('a::attr(href)').extract_first() + return item + + +def ctx(category=''): + r_url = f"{domain}/{category}" + tree = fetch(r_url) + html = tree.css('body') + posts = tree.css('.list-a').css('li') + channel_title = html.css('a.cur::text').extract_first().strip() + return { + 'title': f'{channel_title} - 新京报', + 'link': r_url, + 'description': f'新京报「{channel_title}」频道新闻', + 'author': 'hillerliao', + 'items': list(map(parse, posts)) + }