コード例 #1
0
    """Return information from files like production-companies.data,
    keywords.data and so on."""
    index = getFullIndex(indexF, movieID, kind='idx2idx')
    if index is None: return []
    result = []
    try:
        fdata = open(dataF, 'rb')
    except IOError, e:
        raise IMDbDataAccessError, str(e)
    fdata.seek(index)
    # Eat the first offset.
    if len(fdata.read(3)) != 3:
        fdata.close()
        return []
    while 1:
        length = convBin(fdata.read(1), 'length')
        strval = latin2utf(fdata.read(length))
        attrid = convBin(fdata.read(3), 'attrID')
        if attrid != 0xffffff:
            attr = getLabel(attrid, attrIF, attrKF)
            if attr: strval += ' %s' % attr
        result.append(strval)
        nextBin = fdata.read(3)
        # There can be multiple values.
        if not (len(nextBin) == 3 and \
                convBin(nextBin, 'movieID') == movieID):
            break
    fdata.close()
    return result

コード例 #2
0
def getMovieMisc(movieID, dataF, indexF, attrIF, attrKF):
    """Return information from files like production-companies.data,
    keywords.data and so on."""
    index = getFullIndex(indexF, movieID, kind='idx2idx')
    if index is None: return []
    result = []
    try:
        fdata = open(dataF, 'rb')
    except IOError, e:
        raise IMDbDataAccessError, str(e)
    fdata.seek(index)
    # Eat the first offset.
    if len(fdata.read(3)) != 3:
        fdata.close()
        return []
    while 1:
        length = convBin(fdata.read(1), 'length')
        strval = latin2utf(fdata.read(length))
        attrid = convBin(fdata.read(3), 'attrID')
        if attrid != 0xffffff:
            attr = getLabel(attrid, attrIF, attrKF)
            if attr: strval += ' %s' % attr
        result.append(strval)
        nextBin = fdata.read(3)
        # There can be multiple values.
        if not (len(nextBin) == 3 and \
                convBin(nextBin, 'movieID') == movieID):
            break
    fdata.close()
    return result
コード例 #3
0
def _convChID(companyID):
    """Return a numeric value for the given string, or None."""
    if companyID is None:
        return None
    return convBin(companyID, 'companyID')
コード例 #4
0
def getCompanyName(companyID, compIF, compDF):
    """Return the company name for the specified companyID or None."""
    try:
        ifptr = open(compIF, 'rb')
    except IOError, e:
        import warnings
        warnings.warn('Unable to access companies information, '
                      'please run the companies4local.py script: %s' % e)
        return None
    ifptr.seek(4L * companyID)
    piddata = ifptr.read(4)
    ifptr.close()
    if len(piddata) != 4:
        return None
    idx = convBin(piddata, 'fulloffset')
    try:
        dfptr = open(compDF, 'rb')
    except IOError, e:
        import warnings
        warnings.warn('Unable to access companies information, '
                      'please run the companies4local.py script: %s' % e)
        return None
    dfptr.seek(idx)
    # Check companyID.
    chID = dfptr.read(3)
    if companyID != convBin(chID, 'companyID'):
        return None
    length = convBin(dfptr.read(2), 'longlength')
    name = latin2utf(dfptr.read(length))
    dfptr.close()
コード例 #5
0
def _convChID(characterID):
    """Return a numeric value for the given string, or None."""
    if characterID is None:
        return None
    return convBin(characterID, 'characterID')
コード例 #6
0
def getCharacterName(characterID, charIF, charDF):
    """Return the character name for the specified characterID or None."""
    try:
        ifptr = open(charIF, 'rb')
    except IOError, e:
        import warnings
        warnings.warn('Unable to access characters information, '
                        'please run the characters4local.py script: %s' % e)
        return None
    ifptr.seek(4L*characterID)
    piddata = ifptr.read(4)
    ifptr.close()
    if len(piddata) != 4:
        return None
    idx = convBin(piddata, 'fulloffset')
    try:
        dfptr = open(charDF, 'rb')
    except IOError, e:
        import warnings
        warnings.warn('Unable to access characters information, '
                        'please run the characters4local.py script: %s' % e)
        return None
    dfptr.seek(idx)
    # Check characterID.
    chID = dfptr.read(3)
    if characterID != convBin(chID, 'characterID'):
        return None
    length = convBin(dfptr.read(2), 'longlength')
    name = latin2utf(dfptr.read(length))
    dfptr.close()
コード例 #7
0
ファイル: companyParser.py プロジェクト: 070499/repo-scripts
def getCompanyName(companyID, compIF, compDF):
    """Return the company name for the specified companyID or None."""
    try:
        ifptr = open(compIF, 'rb')
    except IOError, e:
        import warnings
        warnings.warn('Unable to access companies information, '
                        'please run the companies4local.py script: %s' % e)
        return None
    ifptr.seek(4L*companyID)
    piddata = ifptr.read(4)
    ifptr.close()
    if len(piddata) != 4:
        return None
    idx = convBin(piddata, 'fulloffset')
    try:
        dfptr = open(compDF, 'rb')
    except IOError, e:
        import warnings
        warnings.warn('Unable to access companies information, '
                        'please run the companies4local.py script: %s' % e)
        return None
    dfptr.seek(idx)
    # Check companyID.
    chID = dfptr.read(3)
    if companyID != convBin(chID, 'companyID'):
        return None
    length = convBin(dfptr.read(2), 'longlength')
    name = latin2utf(dfptr.read(length))
    dfptr.close()