def _buildGuests(gl): """Return a list of Movie objects from a list of GA lines.""" rl = [] rlapp = rl.append for g in gl: # When used by the imdbpy2sql.py script, latin_1 strings are passed. if not isinstance(g, UnicodeType): g = unicode(g, 'latin_1', 'replace') titl = re_titleRef.findall(g) if len(titl) != 1: continue note = u'' if g[-1] == ')': opi = g.rfind('(episode') if opi == -1: opi = g.rfind('(') if opi != -1: note = g[opi:].replace('_', '"').strip() g = g[:opi].strip() cr = u'' cri = g.find('_ (qv), as ') if cri != -1: cr = g[cri + 11:].replace('[unknown]', u'').strip() if cr and cr[-1] == ')': opi = cr.rfind('(') if opi != -1: if note: note += ' ' note += cr[opi:] cr = cr[:opi].strip() # As you can see, we've no notion of the movieID, here. m = Movie(title=titl[0], currentRole=cr, notes=note, accessSystem='local') rlapp(m) return rl
def _buildGuests(gl): """Return a list of Movie objects from a list of GA lines.""" rl = [] rlapp = rl.append for g in gl: # When used by the imdbpy2sql.py script, latin_1 strings are passed. if not isinstance(g, unicode): g = unicode(g, 'latin_1', 'replace') titl = re_titleRef.findall(g) if len(titl) != 1: continue note = u'' if g[-1] == ')': opi = g.rfind('(episode') if opi == -1: opi = g.rfind('(') if opi != -1: note = g[opi:].replace('_', '"').strip() g = g[:opi].strip() cr = u'' cri = g.find('_ (qv), as ') if cri != -1: cr = g[cri+11:].replace('[unknown]', u'').strip() if cr and cr[-1] == ')': opi = cr.rfind('(') if opi != -1: if note: note += ' ' note += cr[opi:] cr = cr[:opi].strip() # As you can see, we've no notion of the movieID, here. m = Movie(title=titl[0], currentRole=cr, notes=note, accessSystem='local') rlapp(m) return rl
def _findRefs(self, o, trefs, nrefs): """Find titles or names references in strings.""" if isinstance(o, (unicode, str)): for title in re_titleRef.findall(o): a_title = analyze_title(title, canonical=0) rtitle = build_title(a_title, ptdf=1) if trefs.has_key(rtitle): continue movieID = self._getTitleID(rtitle) if movieID is None: movieID = self._getTitleID(title) if movieID is None: continue m = Movie(title=rtitle, movieID=movieID, accessSystem=self.accessSystem) trefs[rtitle] = m rtitle2 = canonicalTitle(a_title.get('title', u'')) if rtitle2 and rtitle2 != rtitle and rtitle2 != title: trefs[rtitle2] = m if title != rtitle: trefs[title] = m for name in re_nameRef.findall(o): a_name = analyze_name(name, canonical=1) rname = build_name(a_name, canonical=1) if nrefs.has_key(rname): continue personID = self._getNameID(rname) if personID is None: personID = self._getNameID(name) if personID is None: continue p = Person(name=rname, personID=personID, accessSystem=self.accessSystem) nrefs[rname] = p rname2 = normalizeName(a_name.get('name', u'')) if rname2 and rname2 != rname: nrefs[rname2] = p if name != rname and name != rname2: nrefs[name] = p elif isinstance(o, (list, tuple)): for item in o: self._findRefs(item, trefs, nrefs) elif isinstance(o, dict): for value in o.values(): self._findRefs(value, trefs, nrefs) return (trefs, nrefs)
def _findRefs(self, o, trefs, nrefs): """Find titles or names references in strings.""" if isinstance(o, (UnicodeType, StringType)): for title in re_titleRef.findall(o): a_title = analyze_title(title, canonical=1) rtitle = build_title(a_title, canonical=1, ptdf=1) if trefs.has_key(rtitle): continue movieID = self._getTitleID(rtitle) if movieID is None: movieID = self._getTitleID(title) if movieID is None: continue m = Movie(title=rtitle, movieID=movieID, accessSystem=self.accessSystem) trefs[rtitle] = m rtitle2 = canonicalTitle(a_title.get('title', u'')) if rtitle2 and rtitle2 != rtitle and rtitle2 != title: trefs[rtitle2] = m if title != rtitle: trefs[title] = m for name in re_nameRef.findall(o): a_name = analyze_name(name, canonical=1) rname = build_name(a_name, canonical=1) if nrefs.has_key(rname): continue personID = self._getNameID(rname) if personID is None: personID = self._getNameID(name) if personID is None: continue p = Person(name=rname, personID=personID, accessSystem=self.accessSystem) nrefs[rname] = p rname2 = normalizeName(a_name.get('name', u'')) if rname2 and rname2 != rname: nrefs[rname2] = p if name != rname and name != rname2: nrefs[name] = p elif isinstance(o, (ListType, TupleType)): for item in o: self._findRefs(item, trefs, nrefs) elif isinstance(o, DictType): for value in o.values(): self._findRefs(value, trefs, nrefs) return (trefs, nrefs)