From 0e194cb9edeca10cb1d4cd907af5b7c3e45a6a0a Mon Sep 17 00:00:00 2001 From: hillerliao Date: Sat, 4 Apr 2020 19:58:56 +0800 Subject: [PATCH] techcrunch --- README.md | 2 +- rsshub/blueprints/main.py | 7 ++++++- rsshub/spiders/techcrunch/tag.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 rsshub/spiders/techcrunch/tag.py diff --git a/README.md b/README.md index e3a6ba5..f3b0ac3 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,6 @@ flask run ### 部署到Heroku -[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/alphardex/RSSHub-python) +[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/hillerliao/RSSHub-python) 记得在环境变量中把FLASK_CONFIG设为production diff --git a/rsshub/blueprints/main.py b/rsshub/blueprints/main.py index 0f61007..29eb4b3 100644 --- a/rsshub/blueprints/main.py +++ b/rsshub/blueprints/main.py @@ -114,4 +114,9 @@ def cls_subject(category=''): @bp.route('/chaindd/column/') def chaindd_column(category=''): from rsshub.spiders.chaindd.column import ctx - return render_template('main/atom.xml', **filter_content(ctx(category))) \ No newline at end of file + return render_template('main/atom.xml', **filter_content(ctx(category))) + +@bp.route('/techcrunch/tag/') +def techcrunch_tag(category=''): + from rsshub.spiders.techcrunch.tag import ctx + return render_template('main/atom.xml', **filter_content(ctx(category))) diff --git a/rsshub/spiders/techcrunch/tag.py b/rsshub/spiders/techcrunch/tag.py new file mode 100644 index 0000000..4ad8742 --- /dev/null +++ b/rsshub/spiders/techcrunch/tag.py @@ -0,0 +1,28 @@ +import requests +import json +from rsshub.utils import DEFAULT_HEADERS + +domain = 'https://techcrunch.com' + +def parse(post): + item = {} + item['title'] = post['title']['rendered'] + item['description'] = post['content']['rendered'] + item['link'] = post['link'] + item['pubDate'] = post['date_gmt'] + return item + +def ctx(category=''): + url = f'{domain}/wp-json/tc/v1/magazine?tags={category}' + res = requests.get(url, headers=DEFAULT_HEADERS) + res = json.loads(res.text) + posts = res + print(posts) + items = list(map(parse, posts)) + return { + 'title': f'{category} - tag - Techcrunch', + 'description': f'{category} - tag - Techcrunch', + 'link': f'f{domain}/tag/fintech/', + 'author': f'hillerliao', + 'items': items + } \ No newline at end of file