Skip to content

Commit

Permalink
poe: remove french
Browse files Browse the repository at this point in the history
poe.ninja appears to no longer support it
  • Loading branch information
raylu committed Sep 15, 2023
1 parent 700bd0d commit 4869f42
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
2 changes: 1 addition & 1 deletion mock_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ def __init__(self):
'cats': {'position': 2, 'name': 'cats', 'color': 13369480, 'id': '2222'},
}

poe.poedb(MockCmd())
poe.price(MockCmd())
28 changes: 5 additions & 23 deletions poe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import html.parser
import time
import typing

import requests

Expand Down Expand Up @@ -122,9 +123,9 @@ def _search(league, q) -> tuple[set[str], list[dict]]:

pages = {}

def _page(league, q):
def _page(league, q) -> tuple[typing.Optional[str], set[str], typing.Optional[str]]:
if len(pages) == 0:
r = rs.get('https://poe.ninja/api/data/economysearch', params={'league': league, 'language': 'fr'})
r = rs.get('https://poe.ninja/api/data/economysearch', params={'league': league})
r.raise_for_status()
pages.update(r.json())

Expand All @@ -135,30 +136,11 @@ def _page(league, q):
# there may be other matches on other pages, but we won't bother finding them
return q, names, page

# couldn't find it in english; try french
fr_q = []
for en, fr in pages['language']['translations'].items():
fr = fr.casefold()
if q == fr:
fr_q = [(en.casefold(), fr)]
break
elif q in fr:
fr_q.append((en.casefold(), fr))
if len(fr_q) == 1:
q = fr_q[0][0]
for page, items in pages['items'].items():
for item in items:
if q in item['name'].casefold():
return q, names, page
elif len(fr_q) > 1:
names = {fr for en, fr in fr_q}
return None, names, None
else:
return None, names, None
return None, names, None

cache = {}

def _query(page, league):
def _query(page: str, league):
cached = cache.get((page, league))
now = time.time()
if cached is not None:
Expand Down
7 changes: 3 additions & 4 deletions tests/test_poe.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def assert_reply(self, q, value=None, matches=None):

def test_price(self):
self.assert_reply('the strat', 'The Strategist: 125.0 chaos')
self.assert_reply('le stratège', 'The Strategist: 125.0 chaos')
self.assert_reply('of mirror', 'House of Mirrors: 3570.6 chaos, 21.0 divine')

def test_exact(self):
self.assert_reply('enlighten support', '''
Expand All @@ -58,8 +58,7 @@ def test_multi_match(self):
'Exalted Orb',
'Exalted Shard',
])
self.assert_reply('promesse d',
matches=["promesse d'atziri", 'la promesse du lapidaire', 'promesse de gangresang'])
self.assert_reply('promise', matches=["Gemcutter's Promise", 'Broken Promises'])

def test_no_match(self):
self.assert_reply('fishing', matches=["couldn't find fishing"])
Expand All @@ -79,7 +78,7 @@ def get(url, params=None):
with open(path.join(fixtures_dir, 'index_state.json')) as f:
data = json.load(f)
return mock.Mock(json=mock.Mock(return_value=data))
elif url == 'https://poe.ninja/api/data/economysearch' and params == {'league': 'Kalandra', 'language': 'fr'}:
elif url == 'https://poe.ninja/api/data/economysearch' and params == {'league': 'Kalandra'}:
with open(path.join(fixtures_dir, 'economysearch_kalandra_fr.json')) as f:
data = json.load(f)
return mock.Mock(json=mock.Mock(return_value=data))
Expand Down

0 comments on commit 4869f42

Please sign in to comment.