Skip to content

Commit

Permalink
remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
binjie09 committed Mar 23, 2023
1 parent 452373c commit 26650eb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
# duckduckgo-api


[![Deploy to Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/binjie09/duckduckgo-api)

<details>
<summary>设置 Vercel 的指导</summary>

1. 前往 [vercel.com](https://vercel.com/)
1. 点击 `Log in`
![](https://files.catbox.moe/tct1wg.png)
1. 点击 `Continue with GitHub` 通过 GitHub 进行登录
![](https://files.catbox.moe/btd78j.jpeg)
1. 登录 GitHub 并允许访问所有存储库(如果系统这样提示)
1. Fork 这个仓库
1. 返回到你的 [Vercel dashboard](https://vercel.com/dashboard)
1. 选择 `Import Project`
![](https://files.catbox.moe/qckos0.png)
1. 选择 `Import Git Repository`
![](https://files.catbox.moe/pqub9q.png)
1. 选择 root 并将所有内容保持不变,并且只需添加名为 PAT_1 的环境变量(如图所示),其中将包含一个个人访问令牌(PAT),你可以在[这里](https://github.com/settings/tokens/new)轻松创建(保留默认,并且只需要命名下,名字随便)
![](https://files.catbox.moe/0ez4g7.png)
1. 点击 deploy,这就完成了,查看你的域名就可使用 API 了!

</details>

use docker

```
Expand Down
2 changes: 1 addition & 1 deletion api/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@app.route('/search')
def hello_world(): # put application's code here
def search(): # put application's code here
from duckduckgo_search import ddg

keywords = request.args.get('q')
Expand Down
16 changes: 3 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
from flask import Flask, request

from api.index import search
app = Flask(__name__)


@app.route('/search')
def hello_world(): # put application's code here
from duckduckgo_search import ddg

keywords = request.args.get('q')
print(request.args.get('max_results'))
max_results = int(request.args.get('max_results') or "3")
results = ddg(keywords, region='wt-wt', max_results=max_results)
print(results)
return results

app.route('/search')(search)

if __name__ == '__main__':
app.run(host='0.0.0.0')
app.run(host='0.0.0.0', port=8000)

0 comments on commit 26650eb

Please sign in to comment.