add type to infoq search query

This commit is contained in:
hillerliao
2022-10-22 10:04:55 +08:00
parent a38d458e7d
commit 8f1c772524
3 changed files with 10 additions and 9 deletions

View File

@@ -73,10 +73,10 @@ def infoq_profile(category=''):
from rsshub.spiders.infoq.profile import ctx
return render_template('main/atom.xml', **filter_content(ctx(category)))
@bp.route('/infoq/search/<string:category>')
def infoq_search(category=''):
@bp.route('/infoq/search/<string:category>/<int:type>')
def infoq_search(category='', type=''):
from rsshub.spiders.infoq.search import ctx
return render_template('main/atom.xml', **filter_content(ctx(category)))
return render_template('main/atom.xml', **filter_content(ctx(category, type)))
@bp.route('/dxzg/notice')
def dxzg_notice():

View File

@@ -17,18 +17,18 @@ def parse(post):
return item
def ctx(category=''):
def ctx(category='', type=''):
# category = unquote(category, encoding='utf-8')
category1 = category.encode("utf-8").decode("latin-1")
referer = f'{domain}/search/c=0/k={category1}/t=0'
referer = f'{domain}/search/c=0/k={category1}/t={type}'
DEFAULT_HEADERS.update({'Referer': referer})
url = f'{domain}/api/gksearch/search'
payload = {"q":category,"t":0,"s":20,"p":1}
payload = {"q":category,"t": type,"s":20,"p":1}
posts = requests.post(url, json=payload, headers=DEFAULT_HEADERS)
posts = json.loads(posts.text)['data']['list']
return {
'title': f'{category} - 搜索 - InfoQ',
'link': referer,
'link': f'{domain}/search/c=0/k={category}/t=0',
'description': f'{category} - 极客邦搜索 - InfoQ',
'author': 'hillerliao',
'items': list(map(parse, posts))

View File

@@ -124,8 +124,9 @@
<p class="card-text">路由:<code>/infoq/profile/:category</code></p>
<h6 class="text-muted">搜索结果<a href="https://github.com/hillerliao" target="_blank" class="badge badge-secondary">by hillerliao</a></h6>
<p class="card-text">举例:<a href="https://pyrsshub.vercel.app/infoq/search/金融" target="_blank">https://pyrsshub.vercel.app/infoq/search/金融</a></p>
<p class="card-text">路由:<code>/infoq/search/:category</code></p>
<p class="card-text">举例:<a href="https://pyrsshub.vercel.app/infoq/search/金融/2" target="_blank">https://pyrsshub.vercel.app/infoq/search/金融/2</a></p>
<p class="card-text">路由:<code>/infoq/search/:category/:type</code></p>
<p class="card-text">参数category [必填,关键词]type [必填类型0 全部 | 1 微信公众号 | 2 infoQ网站 ]</p>
</div>
</div>
<br>