Skip to content

Commit

Permalink
Simplified the auto loading of the xml files. In the old situation do…
Browse files Browse the repository at this point in the history
…wnload_anime_list was never called, as the file always exists. download_anime_list had already expiration of cache included. So now it's also used.
  • Loading branch information
p0psicles committed Oct 24, 2016
1 parent ddf9b16 commit e0f30f2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CHANGES
=======

* Updated changelog
* Added method for refreshing the xml_lists
* Updated Changelog
* Fixed search by aid and by tvdbid
Expand Down
19 changes: 3 additions & 16 deletions simpleanidb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ def __init__(self, session=None, cache_dir=None, auto_download=True, lang=None):
self.session = session or requests.Session()
self.session.headers.setdefault('user-agent', 'simpleanidb/{0}.{1}.{2}'.format(*__version__))

self.anime_titles_path = os.path.join(
self._cache_dir, 'anime-titles.xml.gz')
self.anime_list_path = os.path.join(
self._cache_dir, 'anime-list.xml.gz')
self.auto_download = auto_download
self._xml_titles = self._xml = None
self._xml_list = None
Expand Down Expand Up @@ -73,18 +69,9 @@ def _load_xml(self, url, force=False):
local_file = os.path.join(self._cache_dir, url.split('/')[-1])
xml = None

if not force:
try:
xml = self._read_file(local_file)
except IOError:
if self.auto_download:
self.download_anime_list(local_file, url)
xml = self._read_file(local_file)
else:
raise
else:
self.download_anime_list(local_file, url)
xml = self._read_file(local_file)
if self.auto_download:
self.download_anime_list(local_file, url, force)
xml = self._read_file(local_file)

return xml

Expand Down

0 comments on commit e0f30f2

Please sign in to comment.