mirror of
https://github.com/wassname/compleat.git
synced 2026-06-27 18:23:18 +08:00
87 lines
2.6 KiB
Markdown
87 lines
2.6 KiB
Markdown
# compleat
|
|
|
|
Fetch autocomplete suggestions from Google Search. Use responsibly. Not affiliated with Google.
|
|
|
|
## Installation
|
|
|
|
`pip install compleat`
|
|
|
|
## Usage
|
|
|
|
`compleat` can be used as either a Python library or command-line tool.
|
|
|
|
### Library
|
|
|
|
```python
|
|
>>> import compleat
|
|
>>> q = compleat.suggest("is allen iverson ")
|
|
>>> q.meta
|
|
{
|
|
'lang': 'en',
|
|
'query': 'is allen iverson ',
|
|
'uid': '2c83d58b7350a9f55066cf4f49d16fd9',
|
|
'timestamp': 'Fri Jan 31 00:13:00 2014'
|
|
}
|
|
>>> len(q.suggestions)
|
|
20
|
|
>>> q.suggestions[0:5]
|
|
[{'relevance': 800,
|
|
'text': u'is allen iverson broke',
|
|
'title': u'',
|
|
'type': u'QUERY'},
|
|
{'relevance': 601,
|
|
'text': u'is allen iverson really broke',
|
|
'title': u'',
|
|
'type': u'QUERY'},
|
|
{'relevance': 600,
|
|
'text': u'is allen iverson still broke',
|
|
'title': u'',
|
|
'type': u'QUERY'},
|
|
{'relevance': 566,
|
|
'text': u'is allen iverson still in the nba',
|
|
'title': u'',
|
|
'type': u'QUERY'},
|
|
{'relevance': 565,
|
|
'text': u'is allen iverson back in the nba',
|
|
'title': u'',
|
|
'type': u'QUERY'}]
|
|
```
|
|
|
|
Note: `compleat.suggest()` also accepts an optional `lang` parameter, which is "en" (English) by default.
|
|
|
|
```python
|
|
>>> import compleat
|
|
>>> [ s["text"] for s in compleat.suggest("bon", lang="en").suggestions[:5] ]
|
|
['bones', 'bonnie and clyde', 'bonobos', 'bon appetit', 'bonefish grill']
|
|
>>> [ s["text"] for s in compleat.suggest("bon", lang="fr").suggestions[:5] ]
|
|
['bon coin', 'bonobo', 'bon prix', 'bon patron', 'bonnet']
|
|
>>> [ s["text"] for s in compleat.suggest("bon", lang="es").suggestions[:5] ]
|
|
['bonoloto', 'bonus', 'bon jovi', 'bones', 'bonsai']
|
|
```
|
|
|
|
Note: `compleat.suggest()` also accepts an optional `site` parameter, which is "" (Google) by default. Others include `bo` for google books, `i` for google images, and `yt` for youtube, as well as `n` for news, `pr`, `sh` for shopping, `v` for videos.
|
|
|
|
```python
|
|
>>> import compleat
|
|
>>> [ s["text"] for s in compleat.suggest("bon", site="yt").suggestions[:5] ]
|
|
['bon jovi', 'bone thugs n harmony', 'bonetrousle', 'bones', 'bon iver']
|
|
>>> [ s["text"] for s in compleat.suggest("bon", site="bo").suggestions[:5] ]
|
|
['bone', 'bonhoeffer', 'bonnie and clyde', 'bond', 'bonsai']
|
|
>>> [ s["text"] for s in compleat.suggest("bon", site="i").suggestions[:5] ]
|
|
['bonnie wright', 'bonnie and clyde', 'bonsai', 'bong', 'bone']
|
|
```
|
|
|
|
### Command-line tool
|
|
|
|
Run `compleat -h` from the command line for full set of options. Examples:
|
|
|
|
`compleat -q "where is "`
|
|
|
|
`compleat -q "where is " --json`
|
|
|
|
`compleat -q "where is " --db sqlite:///whereis.sqlite`
|
|
|
|
`compleat -q "who is " "why is " "where is "`
|
|
|
|
`compleat --template "is {} " -q "allen iverson" "marie curie" "meryl streep"`
|