Skip to content

Commit

Permalink
full text search
Browse files Browse the repository at this point in the history
  • Loading branch information
mtimkovich committed Dec 4, 2018
1 parent e857c43 commit 59f534d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@ env
config.yml
cards.json
hs_storage.txt
*.db
25 changes: 10 additions & 15 deletions hearthsounds.py
Expand Up @@ -37,25 +37,20 @@ def img(self):
return ('https://media.services.zam.com/v1/media/byName/'
'hs/cards/enus/{}.png'.format(self.id))

def sound_url(self, file_name):
return self.URL_BASE + file_name

def search_name(self):
"""The name used when searching the sound files."""
return self.name.replace(' ', '')

def find_sounds(self, db):
# TODO: add some deduping.
query = 'select * from sounds where file_name match ?'
prefixes = ['VO_{}_'.format(self.id), self.id, self.search_name()]
for prefix in prefixes:
prefix = '^{}*'.format(prefix)
for row in db.execute(query, (prefix,)):
self.add_sound(row[0])

# Legendary cards have stingers that accompany the voice line.
# TODO: Search for group stingers e.g. Alliance.
if self.rarity == 'LEGENDARY':
pattern = re.compile(self.name.replace(' ', '_?'))
for row in db.execute(query, ('^Pegasus_*',)):
if pattern.search(row[0]):
sql = 'select * from sounds where file_name match ?'
terms = [self.id, self.search_name(), self.name.replace(' ', '_')]
for term in terms:
term = '{}*'.format(term)
for row in db.execute(sql, (term,)):
if self.sound_url(row[0]) not in self.sounds.values():
self.add_sound(row[0])

def add_sound(self, name):
Expand All @@ -78,7 +73,7 @@ def add_sound(self, name):
type_str = '{} {}'.format(type, n)

if type_str not in self.sounds:
self.sounds[type_str] = self.URL_BASE + name
self.sounds[type_str] = self.sound_url(name)
return
n += 1

Expand Down

0 comments on commit 59f534d

Please sign in to comment.