upload_to_commons.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:toollabs 作者: multichill 项目源码 文件源码
def findDuplicateImages(photo=None, site=wikipedia.getSite()):
    '''
    Takes the photo, calculates the SHA1 hash and asks the mediawiki api for a list of duplicates.

    TODO: Add exception handling, fix site thing
    '''
    result = []
    hashObject = hashlib.sha1()
    hashObject.update(photo.getvalue())
    sha1Hash = base64.b16encode(hashObject.digest())

    params = {
    'action'    : 'query',
        'list'      : 'allimages',
        'aisha1'    : sha1Hash,
        'aiprop'    : '',
    }
    data = query.GetData(params, site=wikipedia.getSite(), useAPI = True, encodeTitle = False)
    for image in data['query']['allimages']:
        result.append(image['name'])
    return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号