logohunter 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- logohunter-0.1.2/PKG-INFO +258 -0
- logohunter-0.1.2/README.md +217 -0
- logohunter-0.1.2/pyproject.toml +130 -0
- logohunter-0.1.2/src/logohunter/__init__.py +21 -0
- logohunter-0.1.2/src/logohunter/hunter.py +886 -0
- logohunter-0.1.2/src/logohunter/logo_hunter.egg-info/PKG-INFO +277 -0
- logohunter-0.1.2/src/logohunter/logo_hunter.egg-info/SOURCES.txt +8 -0
- logohunter-0.1.2/src/logohunter/logo_hunter.egg-info/dependency_links.txt +1 -0
- logohunter-0.1.2/src/logohunter/logo_hunter.egg-info/requires.txt +3 -0
- logohunter-0.1.2/src/logohunter/logo_hunter.egg-info/top_level.txt +1 -0
- logohunter-0.1.2/src/logohunter/rules/__init__.py +1 -0
- logohunter-0.1.2/src/logohunter/rules/dimensions/__init__.py +1 -0
- logohunter-0.1.2/src/logohunter/rules/dimensions/bonus.py +43 -0
- logohunter-0.1.2/src/logohunter/rules/dimensions/bonuses.txt +1 -0
- logohunter-0.1.2/src/logohunter/rules/dimensions/penalties.txt +6 -0
- logohunter-0.1.2/src/logohunter/rules/dimensions/penalty.py +205 -0
- logohunter-0.1.2/src/logohunter/rules/html/__init__.py +1 -0
- logohunter-0.1.2/src/logohunter/rules/html/bonus.py +163 -0
- logohunter-0.1.2/src/logohunter/rules/html/bonuses.txt +7 -0
- logohunter-0.1.2/src/logohunter/rules/html/penalties.txt +6 -0
- logohunter-0.1.2/src/logohunter/rules/html/penalty.py +238 -0
- logohunter-0.1.2/src/logohunter/scoring.py +171 -0
- logohunter-0.1.2/src/logohunter/test_hunter.py +553 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: logohunter
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: A modern, async Python library for fetching and processing customer logos from websites.
|
|
5
|
+
Keywords: logo,web scraping,image processing,async,httpx,favicon
|
|
6
|
+
Author: Petri Savolainen
|
|
7
|
+
Author-email: Petri Savolainen <petri@koodaamo.fi>
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
20
|
+
Classifier: Framework :: AsyncIO
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Dist: httpx>=0.24.1
|
|
24
|
+
Requires-Dist: selectolax>=0.3.29
|
|
25
|
+
Requires-Dist: pillow>=9.5.0
|
|
26
|
+
Requires-Dist: rich>=13.0.0
|
|
27
|
+
Requires-Dist: pytest>=7.0.0 ; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest-asyncio>=0.21.0 ; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-cov>=4.0.0 ; extra == 'dev'
|
|
30
|
+
Requires-Dist: black>=23.0.0 ; extra == 'dev'
|
|
31
|
+
Requires-Dist: ruff>=0.1.0 ; extra == 'dev'
|
|
32
|
+
Requires-Dist: mypy>=1.0.0 ; extra == 'dev'
|
|
33
|
+
Requires-Python: >=3.12
|
|
34
|
+
Project-URL: Homepage, https://github.com/koodaamo/logohunter
|
|
35
|
+
Project-URL: Documentation, https://github.com/koodaamo/logohunter#readme
|
|
36
|
+
Project-URL: Repository, https://github.com/koodaamo/logohunter
|
|
37
|
+
Project-URL: Bug Tracker, https://github.com/koodaamo/logohunter/issues
|
|
38
|
+
Project-URL: Changelog, https://github.com/koodaamo/logohunter/releases
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Description-Content-Type: text/markdown
|
|
41
|
+
|
|
42
|
+
# LogoHunter 🎯
|
|
43
|
+
|
|
44
|
+
An async Python library and CLI for discovering and processing high-quality customer logos from websites.
|
|
45
|
+
|
|
46
|
+
- Library: programmatic API to find, score, and fetch the best logo for a domain
|
|
47
|
+
- CLI: quick, pretty terminal tool to inspect candidates and save the best logo
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## Features
|
|
51
|
+
|
|
52
|
+
- Async discovery with httpx and selectolax (fast, non-blocking)
|
|
53
|
+
- Multi-source discovery:
|
|
54
|
+
- Web App Manifest icons
|
|
55
|
+
- Apple Touch icons
|
|
56
|
+
- Standard favicon declarations (including SVG)
|
|
57
|
+
- Open Graph / social tags
|
|
58
|
+
- Heuristics for logo images in the DOM (classes/ids/alt)
|
|
59
|
+
- Common fallback paths
|
|
60
|
+
- Rule-based scoring engine (modular bonuses/penalties under `src/logohunter/rules`)
|
|
61
|
+
- Image validation and basic processing with Pillow (LANCZOS resizing)
|
|
62
|
+
- Rich-powered CLI for inspecting candidates and scores
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## Requirements
|
|
66
|
+
|
|
67
|
+
- Python 3.12+
|
|
68
|
+
- Dependencies (installed automatically): httpx, selectolax, Pillow, rich
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
## Installation
|
|
72
|
+
|
|
73
|
+
From source (recommended for now):
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# clone and install in editable mode
|
|
77
|
+
git clone <repository-url>
|
|
78
|
+
cd logohunter
|
|
79
|
+
pip install -e .
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
After install, the CLI command `logohunt` is available. You can also run it with uv:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
uv run logohunt github.com
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Note: If this project is published on PyPI under the same name, you can install with:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install logohunter
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
## Quick Start (Library)
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
import asyncio
|
|
99
|
+
from logohunter import LogoHunter
|
|
100
|
+
|
|
101
|
+
async def main():
|
|
102
|
+
hunter = LogoHunter()
|
|
103
|
+
|
|
104
|
+
# Get the best logo as bytes (PNG/JPEG/WebP for raster images, raw SVG bytes for SVG)
|
|
105
|
+
logo_bytes = await hunter.get_customer_logo(
|
|
106
|
+
"github.com",
|
|
107
|
+
output_format="PNG",
|
|
108
|
+
resize_to=(128, 128),
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
if logo_bytes:
|
|
112
|
+
# Note: If the selected logo is SVG, you'll receive SVG bytes regardless of output_format
|
|
113
|
+
with open("github_logo", "wb") as f:
|
|
114
|
+
f.write(logo_bytes)
|
|
115
|
+
print("Logo saved (extension depends on content: add .png/.svg accordingly)!")
|
|
116
|
+
else:
|
|
117
|
+
print("No logo found")
|
|
118
|
+
|
|
119
|
+
asyncio.run(main())
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
If you specifically need to rasterize SVG to PNG, install a converter (e.g., `cairosvg`) and perform that step yourself. The library currently returns raw SVG bytes when the best logo is an SVG.
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
## Quick Start (CLI)
|
|
126
|
+
|
|
127
|
+
Inspect candidates, see scores, and optionally save the best one.
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# Basic usage
|
|
131
|
+
logohunt github.com
|
|
132
|
+
|
|
133
|
+
# Save best logo to current directory (logo.png/svg)
|
|
134
|
+
logohunt github.com --save
|
|
135
|
+
|
|
136
|
+
# Save to a directory and show all scoring details
|
|
137
|
+
logohunt github.com --save logos/ --all-scores
|
|
138
|
+
|
|
139
|
+
# Verbose mode will also show exceptions if they occur
|
|
140
|
+
logohunt github.com --verbose
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Example CLI output (truncated):
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
LogoHunt • Analyzing github.com
|
|
147
|
+
|
|
148
|
+
📊 Found 5 logo candidates
|
|
149
|
+
#1 • Score: 1240 • SVG
|
|
150
|
+
https://github.com/favicon.svg
|
|
151
|
+
#2 • Score: 860 • PNG (180×180)
|
|
152
|
+
https://github.com/apple-touch-icon.png
|
|
153
|
+
...
|
|
154
|
+
✅ Successfully fetched logo
|
|
155
|
+
💾 Saved to: /path/to/logos/logo.svg
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
## Discovery Strategy
|
|
160
|
+
|
|
161
|
+
LogoHunter collects potential logo icons from multiple sources:
|
|
162
|
+
|
|
163
|
+
1. Web App Manifest (`<link rel="manifest" href="...">` → `icons` array)
|
|
164
|
+
2. Apple Touch icons (`<link rel="apple-touch-icon" ...>`, including precomposed)
|
|
165
|
+
3. Standard favicon declarations (`<link rel="icon" ...>`, SVG preferred when available)
|
|
166
|
+
4. Social/preview images (`og:image`, `twitter:image`) with penalties applied via scoring
|
|
167
|
+
5. Heuristics for DOM images that look like logos
|
|
168
|
+
- Looks for `img` elements in containers with classes/ids like `logo`, `brand`, `header-logo`, `site-logo`, `navbar-brand`, etc.
|
|
169
|
+
- Also considers `alt`, `class`, `id`, and filename keywords containing `logo`
|
|
170
|
+
6. Common fallback paths like `/favicon.svg`, `/logo.svg`, `/favicon.ico`, etc.
|
|
171
|
+
|
|
172
|
+
All discovered candidates are de-duplicated and then scored.
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
## Scoring System (Rule-based)
|
|
176
|
+
|
|
177
|
+
Scoring is modular and data-driven:
|
|
178
|
+
|
|
179
|
+
- Rules live under `src/logohunter/rules/` and are grouped by category (e.g., `html`, `dimensions`).
|
|
180
|
+
- Each category has `bonuses.txt` and `penalties.txt` that define weights, and Python functions that implement the checks.
|
|
181
|
+
- The engine loads all rules and computes a cumulative score with per-rule breakdowns.
|
|
182
|
+
|
|
183
|
+
Examples of current rules and weights (abbreviated):
|
|
184
|
+
|
|
185
|
+
- HTML bonuses (`rules/html/bonuses.txt`):
|
|
186
|
+
- +100 logo_in_filename, +100 logo_in_css_classes, +100 logo_in_element_id, +40 logo_in_alt_text
|
|
187
|
+
- +80 header_proximity, +80 parent_logo_context, +50 brand_keywords
|
|
188
|
+
- HTML penalties (`rules/html/penalties.txt`):
|
|
189
|
+
- -200 social_media_context, -200 single_color_svg, -150 generic_image_names
|
|
190
|
+
- -100 deep_dom_nesting, -75 advertisement_context, -60 content_area_context
|
|
191
|
+
- Dimension rules (`rules/dimensions/*.txt`):
|
|
192
|
+
- +60 apple_touch_icon_sizes
|
|
193
|
+
- -300 social_media_dimensions, -200 banner_dimensions, -150 very_small_images
|
|
194
|
+
- -80 extremely_wide_aspect_ratio, -50 small_images, -20 odd_dimensions
|
|
195
|
+
|
|
196
|
+
The CLI can show a detailed rule breakdown for the top candidates (`--all-scores`).
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
## API Reference
|
|
200
|
+
|
|
201
|
+
Instantiate the hunter and use its async methods.
|
|
202
|
+
|
|
203
|
+
- `await hunter.get_customer_logo(domain, output_format="PNG", resize_to=None, logger=None) -> bytes | None`
|
|
204
|
+
- Discovers, fetches, validates, and processes the best logo.
|
|
205
|
+
- Returns image bytes. If the best logo is SVG, returns the raw SVG bytes.
|
|
206
|
+
|
|
207
|
+
- `await hunter.find_logo_urls(domain) -> list[str]`
|
|
208
|
+
- Returns a list of candidate logo URLs sorted by score (best first).
|
|
209
|
+
|
|
210
|
+
- `await hunter.find_logo_candidates(domain) -> list[Icon]`
|
|
211
|
+
- Returns full candidate objects with scoring details.
|
|
212
|
+
|
|
213
|
+
- `await hunter.fetch_best_logo(urls) -> PIL.Image.Image | str | None`
|
|
214
|
+
- Fetches and validates the best workable logo from the provided URLs.
|
|
215
|
+
- Returns a PIL Image for raster formats, or an SVG string for vector logos.
|
|
216
|
+
|
|
217
|
+
- `LogoHunter.process_image(image, output_format="PNG", resize_to=None) -> bytes`
|
|
218
|
+
- Static method. For PIL images, resizes and encodes to the requested format.
|
|
219
|
+
- For SVG strings, returns the SVG content as UTF‑8 bytes (no rasterization).
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
## Logging
|
|
223
|
+
|
|
224
|
+
- The library logs summary information at INFO and detailed steps at DEBUG.
|
|
225
|
+
- You can pass a custom logger to `get_customer_logo(..., logger=my_logger)` to control output.
|
|
226
|
+
|
|
227
|
+
Example:
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
import logging
|
|
231
|
+
from logohunter import LogoHunter
|
|
232
|
+
|
|
233
|
+
logger = logging.getLogger("my_app")
|
|
234
|
+
logger.setLevel(logging.INFO)
|
|
235
|
+
|
|
236
|
+
hunter = LogoHunter()
|
|
237
|
+
logo_bytes = await hunter.get_customer_logo("github.com", logger=logger)
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
## Contributing
|
|
242
|
+
|
|
243
|
+
- Issues and PRs are welcome.
|
|
244
|
+
- The scoring system is designed to be extensible — contributions to rules are appreciated.
|
|
245
|
+
- Run tests with pytest (see `pyproject.toml` for dev dependencies).
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
## License
|
|
249
|
+
|
|
250
|
+
MIT License - see LICENSE file for details.
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
## Changelog
|
|
254
|
+
|
|
255
|
+
### 0.1.0
|
|
256
|
+
- Initial async library and CLI
|
|
257
|
+
- Modular rule-based scoring engine
|
|
258
|
+
- Rich CLI for candidate inspection and saving
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# LogoHunter 🎯
|
|
2
|
+
|
|
3
|
+
An async Python library and CLI for discovering and processing high-quality customer logos from websites.
|
|
4
|
+
|
|
5
|
+
- Library: programmatic API to find, score, and fetch the best logo for a domain
|
|
6
|
+
- CLI: quick, pretty terminal tool to inspect candidates and save the best logo
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Async discovery with httpx and selectolax (fast, non-blocking)
|
|
12
|
+
- Multi-source discovery:
|
|
13
|
+
- Web App Manifest icons
|
|
14
|
+
- Apple Touch icons
|
|
15
|
+
- Standard favicon declarations (including SVG)
|
|
16
|
+
- Open Graph / social tags
|
|
17
|
+
- Heuristics for logo images in the DOM (classes/ids/alt)
|
|
18
|
+
- Common fallback paths
|
|
19
|
+
- Rule-based scoring engine (modular bonuses/penalties under `src/logohunter/rules`)
|
|
20
|
+
- Image validation and basic processing with Pillow (LANCZOS resizing)
|
|
21
|
+
- Rich-powered CLI for inspecting candidates and scores
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Requirements
|
|
25
|
+
|
|
26
|
+
- Python 3.12+
|
|
27
|
+
- Dependencies (installed automatically): httpx, selectolax, Pillow, rich
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
From source (recommended for now):
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# clone and install in editable mode
|
|
36
|
+
git clone <repository-url>
|
|
37
|
+
cd logohunter
|
|
38
|
+
pip install -e .
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
After install, the CLI command `logohunt` is available. You can also run it with uv:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
uv run logohunt github.com
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Note: If this project is published on PyPI under the same name, you can install with:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install logohunter
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## Quick Start (Library)
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
import asyncio
|
|
58
|
+
from logohunter import LogoHunter
|
|
59
|
+
|
|
60
|
+
async def main():
|
|
61
|
+
hunter = LogoHunter()
|
|
62
|
+
|
|
63
|
+
# Get the best logo as bytes (PNG/JPEG/WebP for raster images, raw SVG bytes for SVG)
|
|
64
|
+
logo_bytes = await hunter.get_customer_logo(
|
|
65
|
+
"github.com",
|
|
66
|
+
output_format="PNG",
|
|
67
|
+
resize_to=(128, 128),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
if logo_bytes:
|
|
71
|
+
# Note: If the selected logo is SVG, you'll receive SVG bytes regardless of output_format
|
|
72
|
+
with open("github_logo", "wb") as f:
|
|
73
|
+
f.write(logo_bytes)
|
|
74
|
+
print("Logo saved (extension depends on content: add .png/.svg accordingly)!")
|
|
75
|
+
else:
|
|
76
|
+
print("No logo found")
|
|
77
|
+
|
|
78
|
+
asyncio.run(main())
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
If you specifically need to rasterize SVG to PNG, install a converter (e.g., `cairosvg`) and perform that step yourself. The library currently returns raw SVG bytes when the best logo is an SVG.
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
## Quick Start (CLI)
|
|
85
|
+
|
|
86
|
+
Inspect candidates, see scores, and optionally save the best one.
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Basic usage
|
|
90
|
+
logohunt github.com
|
|
91
|
+
|
|
92
|
+
# Save best logo to current directory (logo.png/svg)
|
|
93
|
+
logohunt github.com --save
|
|
94
|
+
|
|
95
|
+
# Save to a directory and show all scoring details
|
|
96
|
+
logohunt github.com --save logos/ --all-scores
|
|
97
|
+
|
|
98
|
+
# Verbose mode will also show exceptions if they occur
|
|
99
|
+
logohunt github.com --verbose
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Example CLI output (truncated):
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
LogoHunt • Analyzing github.com
|
|
106
|
+
|
|
107
|
+
📊 Found 5 logo candidates
|
|
108
|
+
#1 • Score: 1240 • SVG
|
|
109
|
+
https://github.com/favicon.svg
|
|
110
|
+
#2 • Score: 860 • PNG (180×180)
|
|
111
|
+
https://github.com/apple-touch-icon.png
|
|
112
|
+
...
|
|
113
|
+
✅ Successfully fetched logo
|
|
114
|
+
💾 Saved to: /path/to/logos/logo.svg
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
## Discovery Strategy
|
|
119
|
+
|
|
120
|
+
LogoHunter collects potential logo icons from multiple sources:
|
|
121
|
+
|
|
122
|
+
1. Web App Manifest (`<link rel="manifest" href="...">` → `icons` array)
|
|
123
|
+
2. Apple Touch icons (`<link rel="apple-touch-icon" ...>`, including precomposed)
|
|
124
|
+
3. Standard favicon declarations (`<link rel="icon" ...>`, SVG preferred when available)
|
|
125
|
+
4. Social/preview images (`og:image`, `twitter:image`) with penalties applied via scoring
|
|
126
|
+
5. Heuristics for DOM images that look like logos
|
|
127
|
+
- Looks for `img` elements in containers with classes/ids like `logo`, `brand`, `header-logo`, `site-logo`, `navbar-brand`, etc.
|
|
128
|
+
- Also considers `alt`, `class`, `id`, and filename keywords containing `logo`
|
|
129
|
+
6. Common fallback paths like `/favicon.svg`, `/logo.svg`, `/favicon.ico`, etc.
|
|
130
|
+
|
|
131
|
+
All discovered candidates are de-duplicated and then scored.
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
## Scoring System (Rule-based)
|
|
135
|
+
|
|
136
|
+
Scoring is modular and data-driven:
|
|
137
|
+
|
|
138
|
+
- Rules live under `src/logohunter/rules/` and are grouped by category (e.g., `html`, `dimensions`).
|
|
139
|
+
- Each category has `bonuses.txt` and `penalties.txt` that define weights, and Python functions that implement the checks.
|
|
140
|
+
- The engine loads all rules and computes a cumulative score with per-rule breakdowns.
|
|
141
|
+
|
|
142
|
+
Examples of current rules and weights (abbreviated):
|
|
143
|
+
|
|
144
|
+
- HTML bonuses (`rules/html/bonuses.txt`):
|
|
145
|
+
- +100 logo_in_filename, +100 logo_in_css_classes, +100 logo_in_element_id, +40 logo_in_alt_text
|
|
146
|
+
- +80 header_proximity, +80 parent_logo_context, +50 brand_keywords
|
|
147
|
+
- HTML penalties (`rules/html/penalties.txt`):
|
|
148
|
+
- -200 social_media_context, -200 single_color_svg, -150 generic_image_names
|
|
149
|
+
- -100 deep_dom_nesting, -75 advertisement_context, -60 content_area_context
|
|
150
|
+
- Dimension rules (`rules/dimensions/*.txt`):
|
|
151
|
+
- +60 apple_touch_icon_sizes
|
|
152
|
+
- -300 social_media_dimensions, -200 banner_dimensions, -150 very_small_images
|
|
153
|
+
- -80 extremely_wide_aspect_ratio, -50 small_images, -20 odd_dimensions
|
|
154
|
+
|
|
155
|
+
The CLI can show a detailed rule breakdown for the top candidates (`--all-scores`).
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
## API Reference
|
|
159
|
+
|
|
160
|
+
Instantiate the hunter and use its async methods.
|
|
161
|
+
|
|
162
|
+
- `await hunter.get_customer_logo(domain, output_format="PNG", resize_to=None, logger=None) -> bytes | None`
|
|
163
|
+
- Discovers, fetches, validates, and processes the best logo.
|
|
164
|
+
- Returns image bytes. If the best logo is SVG, returns the raw SVG bytes.
|
|
165
|
+
|
|
166
|
+
- `await hunter.find_logo_urls(domain) -> list[str]`
|
|
167
|
+
- Returns a list of candidate logo URLs sorted by score (best first).
|
|
168
|
+
|
|
169
|
+
- `await hunter.find_logo_candidates(domain) -> list[Icon]`
|
|
170
|
+
- Returns full candidate objects with scoring details.
|
|
171
|
+
|
|
172
|
+
- `await hunter.fetch_best_logo(urls) -> PIL.Image.Image | str | None`
|
|
173
|
+
- Fetches and validates the best workable logo from the provided URLs.
|
|
174
|
+
- Returns a PIL Image for raster formats, or an SVG string for vector logos.
|
|
175
|
+
|
|
176
|
+
- `LogoHunter.process_image(image, output_format="PNG", resize_to=None) -> bytes`
|
|
177
|
+
- Static method. For PIL images, resizes and encodes to the requested format.
|
|
178
|
+
- For SVG strings, returns the SVG content as UTF‑8 bytes (no rasterization).
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
## Logging
|
|
182
|
+
|
|
183
|
+
- The library logs summary information at INFO and detailed steps at DEBUG.
|
|
184
|
+
- You can pass a custom logger to `get_customer_logo(..., logger=my_logger)` to control output.
|
|
185
|
+
|
|
186
|
+
Example:
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
import logging
|
|
190
|
+
from logohunter import LogoHunter
|
|
191
|
+
|
|
192
|
+
logger = logging.getLogger("my_app")
|
|
193
|
+
logger.setLevel(logging.INFO)
|
|
194
|
+
|
|
195
|
+
hunter = LogoHunter()
|
|
196
|
+
logo_bytes = await hunter.get_customer_logo("github.com", logger=logger)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
## Contributing
|
|
201
|
+
|
|
202
|
+
- Issues and PRs are welcome.
|
|
203
|
+
- The scoring system is designed to be extensible — contributions to rules are appreciated.
|
|
204
|
+
- Run tests with pytest (see `pyproject.toml` for dev dependencies).
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
## License
|
|
208
|
+
|
|
209
|
+
MIT License - see LICENSE file for details.
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
## Changelog
|
|
213
|
+
|
|
214
|
+
### 0.1.0
|
|
215
|
+
- Initial async library and CLI
|
|
216
|
+
- Modular rule-based scoring engine
|
|
217
|
+
- Rich CLI for candidate inspection and saving
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["uv_build>=0.9.3,<12"]
|
|
3
|
+
build-backend = "uv_build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "logohunter"
|
|
7
|
+
version = "0.1.2"
|
|
8
|
+
description = "A modern, async Python library for fetching and processing customer logos from websites."
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "Petri Savolainen", email = "petri@koodaamo.fi" }
|
|
11
|
+
]
|
|
12
|
+
license = { text = "MIT" }
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
requires-python = ">=3.12"
|
|
15
|
+
dependencies = [
|
|
16
|
+
"httpx>=0.24.1",
|
|
17
|
+
"selectolax>=0.3.29",
|
|
18
|
+
"Pillow>=9.5.0",
|
|
19
|
+
"rich>=13.0.0",
|
|
20
|
+
]
|
|
21
|
+
keywords = ["logo", "web scraping", "image processing", "async", "httpx", "favicon"]
|
|
22
|
+
classifiers = [
|
|
23
|
+
"Development Status :: 4 - Beta",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"License :: OSI Approved :: MIT License",
|
|
26
|
+
"Programming Language :: Python",
|
|
27
|
+
"Programming Language :: Python :: 3",
|
|
28
|
+
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Programming Language :: Python :: 3.13",
|
|
30
|
+
"Programming Language :: Python :: 3.14",
|
|
31
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
32
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
33
|
+
"Topic :: Multimedia :: Graphics",
|
|
34
|
+
"Framework :: AsyncIO",
|
|
35
|
+
"Operating System :: OS Independent",
|
|
36
|
+
"Typing :: Typed",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.scripts]
|
|
40
|
+
logohunt = "logohunt:cli_entry"
|
|
41
|
+
|
|
42
|
+
[project.optional-dependencies]
|
|
43
|
+
dev = [
|
|
44
|
+
"pytest>=7.0.0",
|
|
45
|
+
"pytest-asyncio>=0.21.0",
|
|
46
|
+
"pytest-cov>=4.0.0",
|
|
47
|
+
"black>=23.0.0",
|
|
48
|
+
"ruff>=0.1.0",
|
|
49
|
+
"mypy>=1.0.0",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[project.urls]
|
|
53
|
+
Homepage = "https://github.com/koodaamo/logohunter"
|
|
54
|
+
Documentation = "https://github.com/koodaamo/logohunter#readme"
|
|
55
|
+
Repository = "https://github.com/koodaamo/logohunter"
|
|
56
|
+
"Bug Tracker" = "https://github.com/koodaamo/logohunter/issues"
|
|
57
|
+
Changelog = "https://github.com/koodaamo/logohunter/releases"
|
|
58
|
+
|
|
59
|
+
[tool.uv.build-backend]
|
|
60
|
+
wheel-exclude = ["test_*.py", "**/test_*.py", "tests/", "**/tests/"]
|
|
61
|
+
source-exclude = ["__pycache__/", "*.pyc", "*.pyo", ".pytest_cache/"]
|
|
62
|
+
|
|
63
|
+
[tool.black]
|
|
64
|
+
line-length = 88
|
|
65
|
+
target-version = ["py312"]
|
|
66
|
+
include = '\.pyi?$'
|
|
67
|
+
|
|
68
|
+
[tool.ruff]
|
|
69
|
+
target-version = "py312"
|
|
70
|
+
line-length = 88
|
|
71
|
+
select = [
|
|
72
|
+
"E", # pycodestyle errors
|
|
73
|
+
"W", # pycodestyle warnings
|
|
74
|
+
"F", # pyflakes
|
|
75
|
+
"I", # isort
|
|
76
|
+
"B", # flake8-bugbear
|
|
77
|
+
"C4", # flake8-comprehensions
|
|
78
|
+
"UP", # pyupgrade
|
|
79
|
+
]
|
|
80
|
+
ignore = [
|
|
81
|
+
"E501", # line too long, handled by black
|
|
82
|
+
"B008", # do not perform function calls in argument defaults
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
[tool.ruff.per-file-ignores]
|
|
86
|
+
"__init__.py" = ["F401"]
|
|
87
|
+
|
|
88
|
+
[tool.mypy]
|
|
89
|
+
python_version = "3.12"
|
|
90
|
+
warn_return_any = true
|
|
91
|
+
warn_unused_configs = true
|
|
92
|
+
disallow_untyped_defs = true
|
|
93
|
+
disallow_incomplete_defs = true
|
|
94
|
+
check_untyped_defs = true
|
|
95
|
+
disallow_untyped_decorators = true
|
|
96
|
+
no_implicit_optional = true
|
|
97
|
+
warn_redundant_casts = true
|
|
98
|
+
warn_unused_ignores = true
|
|
99
|
+
warn_no_return = true
|
|
100
|
+
warn_unreachable = true
|
|
101
|
+
strict_equality = true
|
|
102
|
+
|
|
103
|
+
[tool.pytest.ini_options]
|
|
104
|
+
minversion = "7.0"
|
|
105
|
+
addopts = "-ra -q --strict-markers --strict-config"
|
|
106
|
+
testpaths = ["src"]
|
|
107
|
+
markers = [
|
|
108
|
+
"asyncio: mark test as async"
|
|
109
|
+
]
|
|
110
|
+
|
|
111
|
+
[tool.coverage.run]
|
|
112
|
+
source = ["src"]
|
|
113
|
+
omit = [
|
|
114
|
+
"*/test_*.py",
|
|
115
|
+
"*/tests/*",
|
|
116
|
+
]
|
|
117
|
+
|
|
118
|
+
[tool.coverage.report]
|
|
119
|
+
exclude_lines = [
|
|
120
|
+
"pragma: no cover",
|
|
121
|
+
"def __repr__",
|
|
122
|
+
"if self.debug:",
|
|
123
|
+
"if settings.DEBUG",
|
|
124
|
+
"raise AssertionError",
|
|
125
|
+
"raise NotImplementedError",
|
|
126
|
+
"if 0:",
|
|
127
|
+
"if __name__ == .__main__.:",
|
|
128
|
+
"class .*\\bProtocol\\):",
|
|
129
|
+
"@(abc\\.)?abstractmethod",
|
|
130
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Top-level package for logohunter.
|
|
2
|
+
|
|
3
|
+
Expose primary classes/functions for convenient imports:
|
|
4
|
+
from logohunter import LogoHunter, Icon, get_scoring_engine
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from importlib.metadata import version, PackageNotFoundError
|
|
8
|
+
|
|
9
|
+
from .hunter import LogoHunter, Icon
|
|
10
|
+
from .scoring import get_scoring_engine
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"LogoHunter",
|
|
14
|
+
"Icon",
|
|
15
|
+
"get_scoring_engine",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
__version__ = version("logohunter")
|
|
20
|
+
except PackageNotFoundError: # pragma: no cover - during editable/dev installs
|
|
21
|
+
__version__ = "0.0.0"
|