def categorizeImage(image, category):
    '''
    Replace uncategorized with a category
    '''
    page = wikipedia.Page(wikipedia.getSite(), u'Image:' + image)
    category = category.replace('_', ' ')
    if page.exists():
        newtext = imagerecat.removeTemplates(page.get())
        newtext = newtext + u'\n[[Category:' + category + ']]'
        comment = u'Adding [[:Category:' + category + u']] from [[' + category + u'|gallery]] to this uncategorized image'
        wikipedia.showDiff(page.get(), newtext)
        page.put(newtext, comment)
def categorizeImage(image, category):
    '''
    Replace uncategorized with a category
    '''
    page = wikipedia.Page(wikipedia.getSite(), u'Image:' + image)
    category = category.replace('_', ' ')
    if page.exists():
	newtext = imagerecat.removeTemplates(page.get())
	newtext = newtext + u'\n[[Category:' + category + ']]'
	comment = u'Adding [[:Category:' + category +  u']] from [[' + category + u'|gallery]] to this uncategorized image'
	wikipedia.showDiff(page.get(), newtext)
	page.put(newtext, comment)
def categorizeImage(image, gals, cats):
    '''
    Replace uncategorized with a category
    '''
    page = wikipedia.Page(wikipedia.getSite(), u'Image:' + image)
    #category = category.replace('_', ' ')
    if (page.exists() and gals and cats):
	newtext = imagerecat.removeTemplates(page.get())
	newtext = newtext + imagerecat.getCheckCategoriesTemplate([], gals, len(cats))
	for category in cats:
	    newtext = newtext + u'[[Category:' + category.replace('_', ' ') + u']]\n'
	comment = u'Adding one or more categories (based on gallery information) to this uncategorized image'
	wikipedia.showDiff(page.get(), newtext)
	try:
	    page.put(newtext, comment)
	except wikipedia.LockedPage:
	    wikipedia.output('Page is locked, skipping')
def categorizeImage(image, gals, cats):
    '''
    Replace uncategorized with a category
    '''
    page = wikipedia.Page(wikipedia.getSite(), u'Image:' + image)
    #category = category.replace('_', ' ')
    if (page.exists() and gals and cats):
        newtext = imagerecat.removeTemplates(page.get())
        newtext = newtext + imagerecat.getCheckCategoriesTemplate([], gals,
                                                                  len(cats))
        for category in cats:
            newtext = newtext + u'[[Category:' + category.replace(
                '_', ' ') + u']]\n'
        comment = u'Adding one or more categories (based on gallery information) to this uncategorized image'
        wikipedia.showDiff(page.get(), newtext)
        try:
            page.put(newtext, comment)
        except wikipedia.LockedPage:
            wikipedia.output('Page is locked, skipping')
Example #5
0
def categorizeImage(page, id, cursor, cursor2):
    # get metadata
    metadata = getMetadata(id, cursor)
    # get current text
    oldtext = page.get()
    # get current categories
    currentCategories =[]
    for cat in page.categories():
	currentCategories.append(cat.titleWithoutNamespace().strip().replace(u' ', u'_'))
    # remove templates
    cleanDescription = wikipedia.removeCategoryLinks(imagerecat.removeTemplates(page.get()), wikipedia.getSite())
    # get new categories
    categories = getCategories(metadata, cursor, cursor2, currentCategories)

    if categories and not set(currentCategories)==set(categories):
	description = cleanDescription + u'\n\n' +  categories
	comment = u'Trying to find better categories for this [[Commons:Batch uploading/Geograph|Geograph]] image'
	wikipedia.output(description)
	wikipedia.showDiff(oldtext, description)
	page.put(description, comment)
Example #6
0
def categorizeImage(page, id, cursor, cursor2):
    # get metadata
    metadata = getMetadata(id, cursor)
    # get current text
    oldtext = page.get()
    # get current categories
    currentCategories = []
    for cat in page.categories():
        currentCategories.append(cat.titleWithoutNamespace().strip().replace(
            u' ', u'_'))
    # remove templates
    cleanDescription = wikipedia.removeCategoryLinks(
        imagerecat.removeTemplates(page.get()), wikipedia.getSite())
    # get new categories
    categories = getCategories(metadata, cursor, cursor2, currentCategories)

    if categories and not set(currentCategories) == set(categories):
        description = cleanDescription + u'\n\n' + categories
        comment = u'Trying to find better categories for this [[Commons:Batch uploading/Geograph|Geograph]] image'
        wikipedia.output(description)
        wikipedia.showDiff(oldtext, description)
        page.put(description, comment)