Skip to content

Commit bfca3eb

Browse files
authored
Merge pull request #40 from opsdisk/migrate-to-pyproject-install
Migrate from setup.py to pyproject.toml
2 parents fc50b08 + 6667883 commit bfca3eb

File tree

6 files changed

+58
-39
lines changed

6 files changed

+58
-39
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ Google's preferred method is to use their [API](https://developers.google.com/cu
3838
pip install yagooglesearch
3939
```
4040

41-
## <span>setup.py</span>
41+
## pyproject.toml
4242

4343
```bash
4444
git clone https://github.com/opsdisk/yagooglesearch
4545
cd yagooglesearch
46-
virtualenv -p python3.7 .venv # If using a virtual environment.
46+
virtualenv -p python3 .venv # If using a virtual environment.
4747
source .venv/bin/activate # If using a virtual environment.
48-
python setup.py install
48+
pip install . # Reads from pyproject.toml
4949
```
5050

5151
## Usage
@@ -75,6 +75,13 @@ for url in urls:
7575
print(url)
7676
```
7777

78+
## Max ~400 results returned
79+
80+
Even though searching Google through the GUI will display a message like "About 13,000,000 results", that does not mean
81+
`yagooglesearch` will find anything close to that. Testing shows that at most, about 400 results are returned. If you
82+
set 400 < `max_search_result_urls_to_return`, a warning message will be printed to the logs. See
83+
<https://github.com/opsdisk/yagooglesearch/issues/28> for the discussion.
84+
7885
## Google is blocking me!
7986

8087
Low and slow is the strategy when executing Google searches using `yagooglesearch`. If you start getting HTTP 429
@@ -297,4 +304,4 @@ Project Link: [https://github.com/opsdisk/yagooglesearch](https://github.com/ops
297304

298305
* [KennBro](https://github.com/KennBro) - <https://github.com/opsdisk/yagooglesearch/pull/9>
299306
* [ArshansGithub](https://github.com/ArshansGithub) - <https://github.com/opsdisk/yagooglesearch/pull/21>
300-
* [pguridi](https://github.com/pguridi) - <https://github.com/opsdisk/yagooglesearch/pull/38>
307+
* [pguridi](https://github.com/pguridi) - <https://github.com/opsdisk/yagooglesearch/pull/38>

pyproject.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[build-system]
2+
requires = ["setuptools"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "yagooglesearch"
7+
dynamic = ["version"]
8+
dependencies = ["beautifulsoup4>=4.9.3", "requests>=2.31.0", "requests[socks]"]
9+
requires-python = ">=3.6"
10+
authors = [{ name = "Brennon Thomas", email = "[email protected]" }]
11+
description = "A Python library for executing intelligent, realistic-looking, and tunable Google searches."
12+
readme = { file = "README.md", content-type = "text/markdown" }
13+
license = { file = "LICENSE" }
14+
keywords = ["python", "google", "search", "googlesearch"]
15+
classifiers = ["Programming Language :: Python"]
16+
17+
[project.urls]
18+
Homepage = "https://github.com/opsdisk/yagooglesearch"
19+
Documentation = "https://github.com/opsdisk/yagooglesearch"
20+
Repository = "https://github.com/opsdisk/yagooglesearch"
21+
22+
[tool.setuptools.dynamic]
23+
version = { attr = "yagooglesearch.__version__" }
24+
25+
[tool.setuptools.packages.find]
26+
where = ["src"]
27+
28+
[tool.setuptools.package-data]
29+
yagooglesearch = ["*.txt"]
30+
31+
[tool.black]
32+
line-length = 120

setup.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

yagooglesearch/__init__.py renamed to src/yagooglesearch/__init__.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
import time
66
import urllib
77

8+
89
# Third party Python libraries.
910
from bs4 import BeautifulSoup
1011
import requests
1112

13+
1214
# Custom Python libraries.
1315

14-
__version__ = "1.8.2"
16+
17+
__version__ = "1.9.0"
1518

1619
# Logging
1720
ROOT_LOGGER = logging.getLogger("yagooglesearch")
@@ -175,10 +178,17 @@ def __init__(
175178
ROOT_LOGGER.warning("The largest value allowed by Google for num is 100. Setting num to 100.")
176179
self.num = 100
177180

181+
if 400 < self.max_search_result_urls_to_return:
182+
ROOT_LOGGER.warning(
183+
"yagooglesearch is usually only able to retrieve a maximum of ~400 results. See README for more details."
184+
)
185+
178186
# Populate cookies with GOOGLE_ABUSE_EXEMPTION if it is provided. Otherwise, initialize cookies to None.
179187
# It will be updated with each request in get_page().
180188
if self.google_exemption:
181-
self.cookies = {"GOOGLE_ABUSE_EXEMPTION": self.google_exemption}
189+
self.cookies = {
190+
"GOOGLE_ABUSE_EXEMPTION": self.google_exemption,
191+
}
182192
else:
183193
self.cookies = None
184194

@@ -312,7 +322,8 @@ def http_429_detected(self):
312322
"""Increase the HTTP 429 cool off period."""
313323

314324
new_http_429_cool_off_time_in_minutes = round(
315-
self.http_429_cool_off_time_in_minutes * self.http_429_cool_off_factor, 2
325+
self.http_429_cool_off_time_in_minutes * self.http_429_cool_off_factor,
326+
2,
316327
)
317328
ROOT_LOGGER.info(
318329
f"Increasing HTTP 429 cool off time by a factor of {self.http_429_cool_off_factor}, "
@@ -321,8 +332,7 @@ def http_429_detected(self):
321332
self.http_429_cool_off_time_in_minutes = new_http_429_cool_off_time_in_minutes
322333

323334
def get_page(self, url):
324-
"""
325-
Request the given URL and return the response page.
335+
"""Request the given URL and return the response page.
326336
327337
:param str url: URL to retrieve.
328338
File renamed without changes.

0 commit comments

Comments
 (0)