Skip to content

Commit

Permalink
libhb: Implementing start/finish dates
Browse files Browse the repository at this point in the history
  • Loading branch information
z411 committed Dec 23, 2014
1 parent 1192187 commit 7a78cbc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion trackma/lib/libhb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from trackma.lib.lib import lib
import trackma.utils as utils
import datetime

import urllib, urllib2
import json
Expand Down Expand Up @@ -124,6 +125,8 @@ def fetch_list(self):
'id': showid,
'title': show['anime']['title'],
'status': self.status_translate[status],
'start_date': self._str2date( show['anime']['started_airing'] ),
'end_date': self._str2date( show['anime']['finished_airing'] ),
'my_progress': show['episodes_watched'],
'my_score': float(rating) if rating is not None else 0.0,
'aliases': alt_titles,
Expand Down Expand Up @@ -199,7 +202,16 @@ def search(self, query):
return infolist
except urllib2.HTTPError, e:
raise utils.APIError('Error searching: ' + str(e.code))


def _str2date(self, string):
if string != '0000-00-00':
try:
return datetime.datetime.strptime(string, "%Y-%m-%d")
except:
return None # Ignore date if it's invalid
else:
return None

def _parse_info(self, show):
info = utils.show()
alt_titles = []
Expand Down

0 comments on commit 7a78cbc

Please sign in to comment.