From 5ae5bd3a84b02d08cc0b530dd70f63f18f964b98 Mon Sep 17 00:00:00 2001 From: j Date: Tue, 1 May 2018 11:59:38 +0200 Subject: [PATCH] refactor aspect ratio parsing --- ox/web/imdb.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ox/web/imdb.py b/ox/web/imdb.py index c8e909b..db0a700 100644 --- a/ox/web/imdb.py +++ b/ox/web/imdb.py @@ -64,6 +64,17 @@ def zebra_table(label, more=None, type='string'): conditions['re'] += more return conditions +def parse_aspectratio(value): + r = value + if ':' in value: + r = value.split(':') + n = r[0] + d = r[1].strip().split(' ')[0] + try: + value = str(float(n) / float(d)) + except: + print('failed to parse aspect: %s' % value) + return value ''' 'posterIds': { @@ -94,7 +105,7 @@ class Imdb(SiteParser): 'page': 'reference', 're': [ 'Aspect Ratio.*?ipl-inline-list__item">\s+([\d\.\:\ ]+)', - lambda r: str(float(r.split(':')[0])/float(r.split(':')[1].split(' ')[0])) if ':' in r else r, + parse_aspectratio, ], 'type': 'float', },