Skip to content

Commit 6d220f6

Browse files
ghuronclaude
andcommitted
Load ADS token from .ads file instead of hardcoding
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 730689a commit 6d220f6

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ __pycache__/
22
*.egg-info/
33
.venv/
44
.vscode/
5+
.ads

src/wdpy/connectors/ads.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
import json
22
import logging
3+
from pathlib import Path
34
from typing import Optional
45
from urllib.request import Request
56
from wdpy import Snak, SourceItem, Statement, build_request
67

8+
_TOKEN_PATH = Path(__file__).parents[3] / '.ads'
9+
_TOKEN = _TOKEN_PATH.read_text().strip() if _TOKEN_PATH.exists() else None
10+
711

812
class ADS(SourceItem):
913
@classmethod
1014
def make_request(cls, ident: Statement) -> Optional[Request]:
15+
if _TOKEN is None:
16+
return None
1117
if url := cls._config["properties"].get(ident.mainsnak.property):
1218
return build_request(
1319
url.format((ident.mainsnak.value or ('',))[0]) +
1420
f'&fl={",".join(ADS._config["fields"])}',
15-
headers={'Authorization': 'Bearer ogOoi0uDxIebyeseB3tAbf5mBTJxXQQWQqE5TW40'}
21+
headers={'Authorization': f'Bearer {_TOKEN}'}
1622
)
1723

1824
def parse(self, text: str, ident: Statement) -> None:

0 commit comments

Comments
 (0)