Skip to content

Commit

Permalink
fontdata_namecheck: use api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rc1e committed Jan 28, 2025
1 parent bdf627a commit 3d23986
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ Below are the noteworthy changes from each release.
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).

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


## 0.13.1 (2025-Jan-17)
Expand Down
22 changes: 8 additions & 14 deletions Lib/fontbakery/checks/fontdata_namecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,18 @@ def check_fontdata_namecheck(ttFont, familyname):
import requests

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

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

0 comments on commit 3d23986

Please sign in to comment.