also parse Year and month year dates

This commit is contained in:
j 2008-07-01 14:40:36 +02:00
parent 4c14ce613d
commit c3874d9a68

View file

@ -313,23 +313,35 @@ def getMovieReleaseDate(imdbId):
first_release = r[1] first_release = r[1]
return first_release return first_release
def _parseDate(d):
try:
parsed_date = time.strptime(d, "%d %B %Y")
parsed_date = time.strftime('%Y-%m-%d', parsed_date)
return parsed_date
except:
try:
parsed_date = time.strptime(d, "%B %Y")
parsed_date = time.strftime('%Y-%m-01', parsed_date)
return parsed_date
except:
pass
try:
parsed_date = time.strptime(d, "%Y")
parsed_date = time.strftime('%Y-01-01', parsed_date)
return parsed_date
except:
pass
return d
def getMovieReleaseDates(imdbId): def getMovieReleaseDates(imdbId):
url = "%s/releaseinfo" % getUrlBase(imdbId) url = "%s/releaseinfo" % getUrlBase(imdbId)
data = getUrlUnicode(url) data = getUrlUnicode(url)
releasedates = [] releasedates = []
regexp = '''<tr><td>(.*?)</td>.*?<td align="right">(.*?)</td>.*?<td>(.*?)</td></tr>''' regexp = '''<tr><td>(.*?)</td>.*?<td align="right">(.*?)</td>.*?<td>(.*?)</td></tr>'''
def _parse_date(d):
try:
parsed_date = time.strptime(d, "%d %B %Y")
parsed_date = time.strftime('%Y-%m-%d', parsed_date)
return parsed_date
except:
return d
for r in re.compile(regexp, re.DOTALL).findall(data): for r in re.compile(regexp, re.DOTALL).findall(data):
r_ = (stripTags(r[0]).strip(), r_ = (stripTags(r[0]).strip(),
_parse_date(stripTags(r[1]).strip()), _parseDate(stripTags(r[1]).strip()),
decodeHtml(stripTags(r[2]).strip())) decodeHtml(stripTags(r[2]).strip()))
releasedates.append(r_) releasedates.append(r_)
return releasedates return releasedates