Exemplo n.º 1
0
 def testTkdialog(self):
     """Test Tk dialog."""
     try:
         box = Tkdialog('foo', 'tests/data/MP_sounds.png', 'MP_sounds.png')
         box.show_dialog()
     except ImportError as e:
         pywikibot.warning(e)
Exemplo n.º 2
0
 def testTkdialog(self):
     """Test Tk dialog."""
     try:
         box = Tkdialog('foo', 'tests/data/MP_sounds.png', 'MP_sounds.png')
         box.show_dialog()
     except ImportError as e:
         pywikibot.warning(e)
Exemplo n.º 3
0
def processPhoto(flickr, photo_id='', flickrreview=False, reviewer='',
                 override='', addCategory='', removeCategories=False,
                 autonomous=False):
    """Process a single Flickr photo."""
    if photo_id:
        pywikibot.output(str(photo_id))
        (photoInfo, photoSizes) = getPhoto(flickr, photo_id)
    if isAllowedLicense(photoInfo) or override:
        # Get the url of the largest photo
        photoUrl = getPhotoUrl(photoSizes)
        # Should download the photo only once
        photo = downloadPhoto(photoUrl)

        # Don't upload duplicate images, should add override option
        duplicates = findDuplicateImages(photo)
        if duplicates:
            pywikibot.output('Found duplicate image at {}'
                             .format(duplicates.pop()))
        else:
            filename = getFilename(photoInfo)
            flinfoDescription = getFlinfoDescription(photo_id)
            photoDescription = buildDescription(flinfoDescription,
                                                flickrreview, reviewer,
                                                override, addCategory,
                                                removeCategories)
            # pywikibot.output(photoDescription)
            if not isinstance(Tkdialog, ImportError) and not autonomous:
                try:
                    (newPhotoDescription, newFilename, skip) = Tkdialog(
                        photoDescription, photo, filename).show_dialog()
                except ImportError as e:
                    pywikibot.warning(e)
                    pywikibot.warning('Switching to autonomous mode.')
                    autonomous = True
            elif not autonomous:
                pywikibot.warning('Switching to autonomous mode because GUI '
                                  'interface cannot be used')
                pywikibot.warning(Tkdialog)
                autonomous = True
            if autonomous:
                newPhotoDescription = photoDescription
                newFilename = filename
                skip = False

            # Do the actual upload
            # Would be nice to check before I upload if the file is already at
            # Commons. Not that important for this program, but maybe for
            # derived programs
            if not skip:
                bot = UploadRobot(photoUrl,
                                  description=newPhotoDescription,
                                  useFilename=newFilename,
                                  keepFilename=True,
                                  verifyDescription=False)
                bot.upload_image(debug=False)
                return 1
    else:
        pywikibot.output('Invalid license')
    return 0
Exemplo n.º 4
0
def processPhoto(photoInfo,
                 panoramioreview=False,
                 reviewer='',
                 override=u'',
                 addCategory=u'',
                 autonomous=False,
                 site=None):
    """Process a single Panoramio photo."""
    if not site:
        site = pywikibot.Site('commons', 'commons')

    if isAllowedLicense(photoInfo) or override:
        # Should download the photo only once
        photo = downloadPhoto(photoInfo.get(u'photo_file_url'))

        # Don't upload duplicate images, should add override option
        duplicates = findDuplicateImages(photo, site=site)
        if duplicates:
            pywikibot.output(u'Found duplicate image at %s' % duplicates.pop())
        else:
            filename = getFilename(photoInfo, site=site)
            pywikibot.output(filename)
            description = getDescription(photoInfo, panoramioreview, reviewer,
                                         override, addCategory)

            pywikibot.output(description)
            if not autonomous:
                (newDescription, newFilename,
                 skip) = Tkdialog(description, photo, filename).show_dialog()
            else:
                newDescription = description
                newFilename = filename
                skip = False


#         pywikibot.output(newPhotoDescription)
#         if (pywikibot.Page(title=u'File:'+ filename,
#                            site=pywikibot.Site()).exists()):
#             # I should probably check if the hash is the same and if not upload
#             # it under a different name
#             pywikibot.output(u'File:' + filename + u' already exists!')
#         else:
# Do the actual upload
# Would be nice to check before I upload if the file is already at
# Commons
# Not that important for this program, but maybe for derived
# programs
            if not skip:
                bot = UploadRobot(photoInfo.get(u'photo_file_url'),
                                  description=newDescription,
                                  useFilename=newFilename,
                                  keepFilename=True,
                                  verifyDescription=False,
                                  site=site)
                bot.upload_image(debug=False)
                return 1
    return 0
Exemplo n.º 5
0
def processPhoto(flickr=None,
                 photo_id=u'',
                 flickrreview=False,
                 reviewer=u'',
                 override=u'',
                 addCategory=u'',
                 removeCategories=False,
                 autonomous=False):
    """Process a single Flickr photo."""
    if photo_id:
        pywikibot.output(str(photo_id))
        (photoInfo, photoSizes) = getPhoto(flickr, photo_id)
    if isAllowedLicense(photoInfo) or override:
        # Get the url of the largest photo
        photoUrl = getPhotoUrl(photoSizes)
        # Should download the photo only once
        photo = downloadPhoto(photoUrl)

        # Don't upload duplicate images, should add override option
        duplicates = findDuplicateImages(photo)
        if duplicates:
            pywikibot.output(u'Found duplicate image at %s' % duplicates.pop())
        else:
            filename = getFilename(photoInfo)
            flinfoDescription = getFlinfoDescription(photo_id)
            photoDescription = buildDescription(flinfoDescription,
                                                flickrreview, reviewer,
                                                override, addCategory,
                                                removeCategories)
            # pywikibot.output(photoDescription)
            if Tkdialog is not None and not autonomous:
                try:
                    (newPhotoDescription, newFilename,
                     skip) = Tkdialog(photoDescription, photo,
                                      filename).show_dialog()
                except ImportError as e:
                    pywikibot.warning(e)
                    pywikibot.warning('Switching to autonomous mode.')
                    autonomous = True
            elif not autonomous:
                pywikibot.warning('Switching to autonomous mode because GUI '
                                  'interface cannot be used')
                pywikibot.warning(_tk_error)
                autonomous = True
            if autonomous:
                newPhotoDescription = photoDescription
                newFilename = filename
                skip = False
        # pywikibot.output(newPhotoDescription)
        # if (pywikibot.Page(title=u'File:'+ filename, site=pywikibot.Site()).exists()):
        # TODO: Check if the hash is the same and if not upload it under a different name
        # pywikibot.output(u'File:' + filename + u' already exists!')
        # else:
        # Do the actual upload
        # Would be nice to check before I upload if the file is already at Commons
        # Not that important for this program, but maybe for derived programs
            if not skip:
                bot = upload.UploadRobot(photoUrl,
                                         description=newPhotoDescription,
                                         useFilename=newFilename,
                                         keepFilename=True,
                                         verifyDescription=False)
                bot.upload_image(debug=False)
                return 1
    else:
        pywikibot.output(u'Invalid license')
    return 0