Skip to content

Commit 0381a24

Browse files
Moved external API URLs to config
1 parent f95a575 commit 0381a24

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

config/default.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@
6060

6161
# Tests
6262
LOAD_WINDOWS_TEST_SQL = False
63+
64+
# External APIs
65+
API_WIKIDATA = 'https://www.wikidata.org/w/api.php'
66+
API_GEONAMES = 'http://api.geonames.org/get'

openatlas/api/external/geonames.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
import xmltodict
55
from flask import g
66

7+
from openatlas import app
8+
79

810
def fetch_geonames(id_: str) -> dict[str, Any]:
9-
url = 'http://api.geonames.org/get'
1011
params = {
1112
'geonameId': {id_},
1213
'username': {g.settings['geonames_username']}}
1314
try:
14-
data = requests.get(url, params, timeout=10).content
15+
data = requests.get(
16+
app.config['API_GEONAMES'],
17+
params,
18+
timeout=10).content
1519
data_dict = xmltodict.parse(data)['geoname']
1620
except Exception: # pragma: no cover
1721
return {}

openatlas/api/external/wikidata.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import requests
44
from flask import g
55

6+
from openatlas import app
67
from openatlas.display.util import link
78

89

@@ -11,15 +12,17 @@ def add_resolver_url(id_: str) -> str:
1112

1213

1314
def fetch_wikidata(id_: str) -> dict[str, Any]:
14-
url = 'https://www.wikidata.org/w/api.php'
1515
params = {
1616
'action': 'wbgetentities',
1717
'ids': id_,
1818
'format': 'json',
1919
'languages': 'en'}
2020
info = {}
2121
try:
22-
data = requests.get(url, params=params, timeout=10).json()
22+
data = requests.get(
23+
app.config['API_WIKIDATA'],
24+
params=params,
25+
timeout=10).json()
2326
except Exception: # pragma: no cover
2427
return {}
2528
try:

tests/test_reference_system.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ def test_reference_system(self) -> None:
2626
data={'id_': '1158433263'})
2727
assert b'Abasgulijev' in rv.data
2828

29-
rv: Any = self.app.get(
30-
url_for('insert', class_='reference_system'))
29+
rv = self.app.get(url_for('insert', class_='reference_system'))
3130
assert b'resolver URL' in rv.data
3231

3332
rv = self.app.post(

0 commit comments

Comments
 (0)