Skip to content

Commit 3d23986

Browse files
committed
fontdata_namecheck: use api endpoint
1 parent bdf627a commit 3d23986

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ Below are the noteworthy changes from each release.
22
A more detailed list of changes is available in the corresponding milestones for each release in the Github issue tracker (https://github.com/googlefonts/fontbakery/milestones?state=closed).
33

44
## Upcoming release: 0.13.2 (2025-Jan-??)
5-
- ...
5+
### Changes to existing checks
6+
### On the Universal profile.
7+
- **[fontdata_namecheck]** Use api endpoint (issues #https://github.com/fonttools/fontbakery/issues/2719#issuecomment-2618877625)
68

79

810
## 0.13.1 (2025-Jan-17)

Lib/fontbakery/checks/fontdata_namecheck.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,18 @@ def check_fontdata_namecheck(ttFont, familyname):
1515
import requests
1616

1717
FB_ISSUE_TRACKER = "https://github.com/fonttools/fontbakery/issues"
18-
NAMECHECK_URL = "http://namecheck.fontdata.com"
18+
API_URL = f"https://namecheck.fontdata.com/api/?q={familyname.replace(' ', '+')}"
19+
HTML_URL = f"http://namecheck.fontdata.com/?q={familyname.replace(' ', '+')}"
1920
try:
20-
# Since October 2019, it seems that we need to fake our user-agent
21-
# in order to get correct query results
22-
FAKE = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1)"
23-
response = requests.post(
24-
NAMECHECK_URL,
25-
params={"q": familyname},
26-
headers={"User-Agent": FAKE},
27-
timeout=10,
28-
)
29-
data = response.content.decode("utf-8")
30-
if "fonts by that exact name" in data:
21+
response = requests.get(API_URL)
22+
data = response.json()
23+
# "1.0" means there is a 100% confidence that the name is already in use
24+
if data["data"]["confidence"]["1.0"] > 0:
3125
yield INFO, Message(
3226
"name-collision",
3327
f'The family name "{familyname}" seems'
3428
f" to be already in use.\n"
35-
f"Please visit {NAMECHECK_URL} for more info.",
29+
f"Please visit {HTML_URL} for more info.",
3630
)
3731
else:
3832
yield PASS, "Font familyname seems to be unique."
@@ -41,7 +35,7 @@ def check_fontdata_namecheck(ttFont, familyname):
4135

4236
yield ERROR, Message(
4337
"namecheck-service",
44-
f"Failed to access: {NAMECHECK_URL}.\n"
38+
f"Failed to access: {API_URL}.\n"
4539
f"\t\tThis check relies on the external service"
4640
f" http://namecheck.fontdata.com via the internet."
4741
f" While the service cannot be reached or does not"

0 commit comments

Comments
 (0)