Skip to content

Commit

Permalink
Moved external API URLs to config
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Aug 7, 2024
1 parent f95a575 commit 0381a24
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@

# Tests
LOAD_WINDOWS_TEST_SQL = False

# External APIs
API_WIKIDATA = 'https://www.wikidata.org/w/api.php'
API_GEONAMES = 'http://api.geonames.org/get'
8 changes: 6 additions & 2 deletions openatlas/api/external/geonames.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
import xmltodict
from flask import g

from openatlas import app


def fetch_geonames(id_: str) -> dict[str, Any]:
url = 'http://api.geonames.org/get'
params = {
'geonameId': {id_},
'username': {g.settings['geonames_username']}}
try:
data = requests.get(url, params, timeout=10).content
data = requests.get(
app.config['API_GEONAMES'],
params,
timeout=10).content
data_dict = xmltodict.parse(data)['geoname']
except Exception: # pragma: no cover
return {}
Expand Down
7 changes: 5 additions & 2 deletions openatlas/api/external/wikidata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import requests
from flask import g

from openatlas import app
from openatlas.display.util import link


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


def fetch_wikidata(id_: str) -> dict[str, Any]:
url = 'https://www.wikidata.org/w/api.php'
params = {
'action': 'wbgetentities',
'ids': id_,
'format': 'json',
'languages': 'en'}
info = {}
try:
data = requests.get(url, params=params, timeout=10).json()
data = requests.get(
app.config['API_WIKIDATA'],
params=params,
timeout=10).json()
except Exception: # pragma: no cover
return {}
try:
Expand Down
3 changes: 1 addition & 2 deletions tests/test_reference_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def test_reference_system(self) -> None:
data={'id_': '1158433263'})
assert b'Abasgulijev' in rv.data

rv: Any = self.app.get(
url_for('insert', class_='reference_system'))
rv = self.app.get(url_for('insert', class_='reference_system'))
assert b'resolver URL' in rv.data

rv = self.app.post(
Expand Down

0 comments on commit 0381a24

Please sign in to comment.