Ejemplo n.º 1
0
def convertList(page):
    '''
    Convert a list of NRHP entries. Both headers and items will be converted.
    '''
    wikipedia.output(u'Working on %s' % page.title())
    
    text = page.get()
    try:
        newtext = convertHeaders(page, text)
        newtext = convertItems(page, newtext)
    except TypeError or AttributeError:
        wikipedia.output(u'One of the regexes failed at %s, skipping this page' % (page.title,))
        traceback.print_exc(file=sys.stdout)
        time.sleep(10)
        return u'Failed'

    if not text==newtext:
        wikipedia.showDiff(text, newtext)
        
        comment = u'Converting list to use [[Template:NRHP header]] and [[Template:NRHP row]]'

        #choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['Yes', 'No'], ['y', 'n'], 'n')
        choice = 'y'

        if choice == 'y':
            #DEBUG
            page.put(newtext, comment)
            return u'Success'
            #wikipedia.output(newtext)

    return u'Unchanged'
Ejemplo n.º 2
0
    def revert(self, item):
        predata = {
            "action": "query",
            "titles": item["title"],
            "prop": "revisions",
            "rvprop": "ids|timestamp|user|content",
            "rvlimit": "2",
            "rvstart": item["timestamp"],
        }
        data = query.GetData(predata, self.site)

        if "error" in data:
            raise RuntimeError(data["error"])

        pages = data["query"].get("pages", ())
        if not pages:
            return False
        page = pages.itervalues().next()
        if len(page.get("revisions", ())) != 2:
            return False
        rev = page["revisions"][1]

        comment = u"Reverted to revision %s by %s on %s" % (rev["revid"], rev["user"], rev["timestamp"])
        if self.comment:
            comment += ": " + self.comment

        page = pywikibot.Page(self.site, item["title"])
        pywikibot.output(
            u"\n\n>>> \03{lightpurple}%s\03{default} <<<" % page.title(asLink=True, forceInterwiki=True, textlink=True)
        )
        old = page.get()
        new = rev["*"]
        pywikibot.showDiff(old, new)
        page.put(new, comment)
        return comment
Ejemplo n.º 3
0
def process_article(page):
    EditMsg = "Robot: Substituting {{[[Template:RS500|RS500]]}} and common fixes"
    wikipedia.setAction(EditMsg)
    try:
        wikitext = page.get()
    except wikipedia.NoPage:
        return
    except wikipedia.IsRedirectPage:
        return
    # Fix Casing (Reduces the number of possible expressions)
    # Common fixes


#		wikitext = commonfixes.fix(wikitext)
# State point.  Count any changes as needing an update if they're after this line
    state0 = wikitext

    # Add |Iran=yes
    wikitext = re.compile(r'\{\{\s*rs500(.*?)\}\}',
                          re.IGNORECASE).sub(r'{{subst:RS500\1}}', wikitext)

    wikipedia.showDiff(page.get(), wikitext)
    if (wikitext != state0):
        try:
            wikipedia.output(u'WRITE:	Adding %s bytes.' %
                             str(len(wikitext) - len(page.get())))
            #				print 'Waiting 2.5 seconds'
            #				time.sleep(2.5)
            page.put(wikitext)
        except TypeError:
            print 'Skipping TypeError'
            return
Ejemplo n.º 4
0
    def tagNowcommons(self, imagepage, filename):
        '''
        Tagged the imag which has been moved to Commons for deletion.
        '''
        if pywikibot.Page(pywikibot.getSite('commons', 'commons'), u'File:' + filename).exists():
            #Get a fresh copy, force to get the page so we dont run into edit conflicts
            imtxt=imagepage.get(force=True)

            #Remove the move to commons templates
            if imagepage.site().language() in moveToCommonsTemplate:
                for moveTemplate in moveToCommonsTemplate[imagepage.site().language()]:
                    imtxt = re.sub(u'(?i)\{\{' + moveTemplate + u'[^\}]*\}\}', u'', imtxt)

            #add {{NowCommons}}
            if imagepage.site().language() in nowCommonsTemplate:
                addTemplate = nowCommonsTemplate[imagepage.site().language()] % filename
            else:
                addTemplate = nowCommonsTemplate['_default'] % filename

            if imagepage.site().language() in nowCommonsMessage:
                commentText = nowCommonsMessage[imagepage.site().language()]
            else:
                commentText = nowCommonsMessage['_default']

            pywikibot.showDiff(imagepage.get(), imtxt + addTemplate)
            imagepage.put(imtxt + addTemplate, comment = commentText)
Ejemplo n.º 5
0
def update_template_coordinates():
    for page in iterate_lists():
        old_text = page.get()
        new_text = old_text
        for data in iterate_monuments_on_page(page):
            old_text = new_text
            try:
                db_data = template_data_to_db_data(data)
                if not has_location(db_data):
                    #szelesseg, hosszusag = get_old_coordinates_for_monument(db_data['azonosito'])
                    hosszusag, szelesseg = get_old_coordinates_for_monument(db_data['azonosito']) # FIXME forditva vannak a DB-ben?
                    pywikibot.output(
                        "adding coordinates: \03{lightyellow}%s\03{default} - %s -> (\03{lightyellow}%s\03{default}, \03{lightyellow}%s\03{default})" 
                        % (db_data['azonosito'], page.title(), szelesseg, hosszusag)
                    )
                    new_text = fill_coordinates_on_page(old_text, db_data['azonosito'], szelesseg, hosszusag)
                    pywikibot.showDiff(old_text, new_text)
            except NoCoordinateForMonument:
                pass
            except pg8000.errors.ProgrammingError:
                raise
            except:
                print db_data
                raise
        page.put(new_text, comment = u'Koordináták beszúrása', botflag=False)
def sort_by_country_subcat(subcat, subject):
    print subcat
    subcat = subcat.replace('_', ' ')
    subject = subject.replace('_', ' ')
    if subcat.startswith(subject):
	temp1 = subcat[len(subject):].lstrip()
	if temp1.startswith('from'):
	    temp2 = temp1[len('from'):].lstrip()
	elif temp1.startswith('of'):
            temp2 = temp1[len('of'):].lstrip()
        elif temp1.startswith('in'):
            temp2 = temp1[len('in'):].lstrip()
	else:
	    temp2 = ''
	if temp2:
	    if temp2.startswith('the'):
		country = temp2[len('the'):].lstrip() 
	    else:
		country = temp2
	    page = wikipedia.Page(wikipedia.getSite(), 'Category:' + subcat)
	    old = u'\[\[[cC]ategory:' + subject + u' by country[^\]]*\]\]'
	    new = u'[[Category:' + subject + u' by country|' + country + u']]'
	    comment = u'Sorting [[:Category:' + subject + u' by country]]'
	    newtext = wikipedia.replaceExcept(page.get(), old, new, [])
	    wikipedia.showDiff(page.get(), newtext)
	    page.put(newtext, comment)
Ejemplo n.º 7
0
    def updateInterwiki (self, wikipediaPage = None, commonsPage = None):
        '''
        Update the interwiki's at commons from a wikipedia page. The bot just
        replaces the interwiki links at the commons page with the interwiki's from
        the wikipedia page. This should probably be more intelligent. We could use
        add all the interwiki's and remove duplicates. Or only remove language links
        if multiple language links to the same language exist.

        This function is disabled for the moment untill i figure out what the best
        way is to update the interwiki's.
        '''
        interwikis = {}
        comment= u''
        interwikilist = wikipediaPage.interwiki()
        interwikilist.append(wikipediaPage)

        for interwikiPage in interwikilist:
            interwikis[interwikiPage.site()]=interwikiPage
        oldtext = commonsPage.get()
        # The commonssite object doesnt work with interwiki's
        newtext = pywikibot.replaceLanguageLinks(oldtext, interwikis,
                                                 pywikibot.getSite(u'nl'))
        comment = u'Updating interwiki\'s from [[' + \
                  wikipediaPage.site().language()  + \
                  u':' + wikipediaPage.title() + u']]'

        if newtext != oldtext:
            #This doesnt seem to work. Newtext has some trailing whitespace
            pywikibot.showDiff(oldtext, newtext)
            commonsPage.put(newtext=newtext, comment=comment)
Ejemplo n.º 8
0
def process_article(page):
		EditMsg = "Robot: Substituting {{[[Template:RS500|RS500]]}} and common fixes"
		wikipedia.setAction(EditMsg)
		try:
			wikitext = page.get()
		except wikipedia.NoPage:
			return
		except wikipedia.IsRedirectPage:
			return
		# Fix Casing (Reduces the number of possible expressions)
		# Common fixes
#		wikitext = commonfixes.fix(wikitext)
		# State point.  Count any changes as needing an update if they're after this line
		state0 = wikitext
 
		# Add |Iran=yes
		wikitext = re.compile(r'\{\{\s*rs500(.*?)\}\}', re.IGNORECASE).sub(r'{{subst:RS500\1}}', wikitext)
 
		wikipedia.showDiff(page.get(), wikitext)
		if (wikitext != state0):
			try:
				wikipedia.output(u'WRITE:	Adding %s bytes.' % str(len(wikitext)-len(page.get())))
#				print 'Waiting 2.5 seconds'
#				time.sleep(2.5)
				page.put(wikitext)	
			except TypeError:
				print 'Skipping TypeError'
				return
Ejemplo n.º 9
0
    def revert(self, item):
        predata = {
            'action': 'query',
            'titles': item['title'],
            'prop': 'revisions',
            'rvprop': 'ids|timestamp|user|content',
            'rvlimit': '2',
            'rvstart': item['timestamp'],
        }
        data = query.GetData(predata, self.site)

        if 'error' in data:
            raise RuntimeError(data['error'])

        pages = data['query'].get('pages', ())
        if not pages: return False
        page = pages.itervalues().next()
        if len(page.get('revisions', ())) != 2: return False
        rev = page['revisions'][1]

        comment = u'Reverted to revision %s by %s on %s' % (rev['revid'],
            rev['user'], rev['timestamp'])
        if self.comment: comment += ': ' + self.comment

        page = pywikibot.Page(self.site, item['title'])
        pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
                         % page.aslink(True, True))
        old = page.get()
        new = rev['*']
        pywikibot.showDiff(old, new)
        page.put(new, comment)
        return comment
Ejemplo n.º 10
0
def replaceCategory (image = None, parents = [], newcat = u''):
    '''
    Remove all parent categories and add newcat
    '''
    result = 0
    newcats = []
    if not newcat == u'':    
        currentCats = imagerecat.getCurrentCats(image)
	workingCategories = currentCats
	workingCategories.append(newcat)
	# Adding parents if the category filter is lagging.
	# The bot often works on new categories. In these cases the filter does know the parent categories
	workingCategories = workingCategories + parents
        for cat in imagerecat.applyAllFilters(workingCategories):
	    #Now remove those parents again
	    if cat not in parents:
                newcats.append(cat)
	if not(set(currentCats)==set(newcats)):
	    newtext = wikipedia.removeCategoryLinks(image.get(), image.site()) + u'\n'
	    for category in newcats:
	        newtext = newtext + u'[[Category:' + category + u']]\n'
	    comment = u'Moving image to (a subcategory of) [[Category:' + newcat + u']] and trying to filter categories'
	    wikipedia.output(image.title())
	    wikipedia.showDiff(image.get(), newtext)
	    image.put(newtext, comment)
            result = 1
    return result
 def save(self, text, page, comment, minorEdit=True, botflag=True):
     # only save if something was changed
     if text != page.get():
         # Show the title of the page we're working on.
         # Highlight the title in purple.
         pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" %
                          page.title())
         # show what was changed
         pywikibot.showDiff(page.get(), text)
         pywikibot.output(u'Comment: %s' % comment)
         try:
             # Save the page
             page.put(text,
                      comment=comment,
                      minorEdit=minorEdit,
                      botflag=botflag)
             return True
         except pywikibot.LockedPage:
             pywikibot.output(u"Page %s is locked; skipping." %
                              page.title(asLink=True))
         except pywikibot.EditConflict:
             pywikibot.output(u'Skipping %s because of edit conflict' %
                              (page.title()))
         except pywikibot.SpamfilterError, error:
             pywikibot.output(
                 u'Cannot change %s because of spam blacklist entry %s' %
                 (page.title(), error.url))
Ejemplo n.º 12
0
    def tagNowcommons(self, imagepage, filename):
        '''
        Tagged the imag which has been moved to Commons for deletion.
        '''
        if pywikibot.Page(pywikibot.getSite('commons', 'commons'), u'File:' + filename).exists():
            #Get a fresh copy, force to get the page so we dont run into edit conflicts
            imtxt=imagepage.get(force=True)

            #Remove the move to commons templates
            if imagepage.site().language() in moveToCommonsTemplate:
                for moveTemplate in moveToCommonsTemplate[imagepage.site().language()]:
                    imtxt = re.sub(u'(?i)\{\{' + moveTemplate + u'[^\}]*\}\}', u'', imtxt)

            #add {{NowCommons}}
            if imagepage.site().language() in nowCommonsTemplate:
                addTemplate = nowCommonsTemplate[imagepage.site().language()] % filename
            else:
                addTemplate = nowCommonsTemplate['_default'] % filename

            if imagepage.site().language() in nowCommonsMessage:
                commentText = nowCommonsMessage[imagepage.site().language()]
            else:
                commentText = nowCommonsMessage['_default']

            pywikibot.showDiff(imagepage.get(), imtxt + addTemplate)
            imagepage.put(imtxt + addTemplate, comment = commentText)
Ejemplo n.º 13
0
def fes(pagina):
    pag = wikipedia.Page(wikipedia.getSite('ca'), pagina) # creem un objecte page on poder treballar
    noutext = text = pag.get() # obtenuim el text
    noutext = re.sub(u"\| ?pàgines ?= p\.?", "|pàgines=", text)
    wikipedia.showDiff(text, noutext)
    if raw_input(u"Vols penjar la pàgina [y/n]?") == "y":
        pag.put(noutext, comment=u"Robot fent canvis per la {{tl|ref-llibre}}")
Ejemplo n.º 14
0
 def treat(self, page):
     # Show the title of the page we're working on.
     # Highlight the title in purple.
     pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" %
                      page.title())
     try:
         oldText = page.get()
         text = oldText
         curpos = 0
         while curpos < len(text):
             match = self.linkR.search(text, pos=curpos)
             if not match:
                 break
             # Make sure that next time around we will not find this same
             # hit.
             curpos = match.start() + 1
             text, jumpToBeginning = self.handleNextLink(text, match)
             if jumpToBeginning:
                 curpos = 0
         if oldText == text:
             pywikibot.output(u'No changes necessary.')
         else:
             pywikibot.showDiff(oldText, text)
             page.put(text, self.comment)
     except pywikibot.NoPage:
         pywikibot.output(u"Page %s does not exist?!" %
                          page.title(asLink=True))
     except pywikibot.IsRedirectPage:
         pywikibot.output(u"Page %s is a redirect; skipping." %
                          page.title(asLink=True))
     except pywikibot.LockedPage:
         pywikibot.output(u"Page %s is locked?!" % page.title(asLink=True))
Ejemplo n.º 15
0
    def tagNowcommons(self, imagepage, filename):
        """
        Tagged the imag which has been moved to Commons for deletion.
        """
        if pywikibot.Page(pywikibot.getSite("commons", "commons"), u"File:" + filename).exists():
            # Get a fresh copy, force to get the page so we dont run into edit conflicts
            imtxt = imagepage.get(force=True)

            # Remove the move to commons templates
            if imagepage.site().language() in moveToCommonsTemplate:
                for moveTemplate in moveToCommonsTemplate[imagepage.site().language()]:
                    imtxt = re.sub(u"(?i)\{\{" + moveTemplate + u"[^\}]*\}\}", u"", imtxt)

            # add {{NowCommons}}
            if imagepage.site().language() in nowCommonsTemplate:
                addTemplate = nowCommonsTemplate[imagepage.site().language()] % filename
            else:
                addTemplate = nowCommonsTemplate["_default"] % filename

            if imagepage.site().language() in nowCommonsMessage:
                commentText = nowCommonsMessage[imagepage.site().language()]
            else:
                commentText = nowCommonsMessage["_default"]

            pywikibot.showDiff(imagepage.get(), imtxt + addTemplate)
            imagepage.put(imtxt + addTemplate, comment=commentText)
Ejemplo n.º 16
0
def sort_by_country_subcat(subcat, subject):
    print subcat
    subcat = subcat.replace('_', ' ')
    subject = subject.replace('_', ' ')
    if subcat.startswith(subject):
        temp1 = subcat[len(subject):].lstrip()
        if temp1.startswith('from'):
            temp2 = temp1[len('from'):].lstrip()
        elif temp1.startswith('of'):
            temp2 = temp1[len('of'):].lstrip()
        elif temp1.startswith('in'):
            temp2 = temp1[len('in'):].lstrip()
        else:
            temp2 = ''
        if temp2:
            if temp2.startswith('the'):
                country = temp2[len('the'):].lstrip()
            else:
                country = temp2
            page = wikipedia.Page(wikipedia.getSite(), 'Category:' + subcat)
            old = u'\[\[[cC]ategory:' + subject + u' by country[^\]]*\]\]'
            new = u'[[Category:' + subject + u' by country|' + country + u']]'
            comment = u'Sorting [[:Category:' + subject + u' by country]]'
            newtext = wikipedia.replaceExcept(page.get(), old, new, [])
            wikipedia.showDiff(page.get(), newtext)
            page.put(newtext, comment)
Ejemplo n.º 17
0
def tagUncategorized(templateTitle):
    site = wikipedia.getSite()
    language = site.language()
    family = site.family.name

    page = wikipedia.Page(wikipedia.getSite(), u'Template:%s' % (templateTitle,))

    if not page.exists() or page.isRedirectPage():
	return False

    text = page.get()
    oldtext = text

    text = text + u'<noinclude>\n\n%s\n</noinclude>' % (uncategorizedTemplate.get(family).get(language), )

    wikipedia.showDiff(oldtext, text)
    try:
        wikipedia.output(page.title())
	page.put(text, editComment.get(family).get(language), maxTries=1)
    except wikipedia.LockedPage:
	return
    except wikipedia.MaxTriesExceededError:
	return
    except wikipedia.EditConflict:
	return
Ejemplo n.º 18
0
def addCoords(sourceWiki, lang, article, lat, lon, region, type, dim):
    '''
    Add the coordinates to article.
    '''

    if (article and lang and type):
        coordTemplate = 'Coordinate'
        site = wikipedia.getSite(lang, 'wikipedia')

        page = wikipedia.Page(site, article)
        try:
            text = page.get()
        except wikipedia.NoPage: # First except, prevent empty pages
            logging.warning('Page empty: %s', article)
            return False
        except wikipedia.IsRedirectPage: # second except, prevent redirect
            logging.warning('Page is redirect: %s', article)
            wikipedia.output(u'%s is a redirect!' % article)
            return False
        except wikipedia.Error: # third exception, take the problem and print
            logging.warning('Some error: %s', article)
            wikipedia.output(u"Some error, skipping..")
            return False       
    
        if coordTemplate in page.templates():
            logging.info('Already has Coordinate template: %s', article)
            return False

        if 'Linn' in page.templates():
            logging.info('Linn template without coords: %s', article)
            return False
            
        newtext = text
        replCount = 1
        coordText = u'{{Coordinate |NS=%s |EW=%s |type=%s |region=%s' % (lat, lon, type, region)
        if (dim):
            coordText += u' |dim=%s' % ( int(dim),)
        coordText += '}}'
        localCatName = wikipedia.getSite().namespace(WP_CATEGORY_NS)
        catStart = r'\[\[(' + localCatName + '|Category):'
        catStartPlain = u'[[' + localCatName + ':'
        replacementText = u''
        replacementText = coordText + '\n\n' + catStartPlain
    
        # insert coordinate template before categories
        newtext = re.sub(catStart, replacementText, newtext, replCount, flags=re.IGNORECASE)

        if text != newtext:
            logging.info('Adding coords to: %s', article)
            comment = u'lisan artikli koordinaadid %s.wikist' % (sourceWiki)
            wikipedia.showDiff(text, newtext)
            modPage = wikipedia.input(u'Modify page: %s ([y]/n) ?' % (article) )
            if (modPage.lower == 'y' or modPage == ''):
                page.put(newtext, comment)
            return True
        else:
            logging.info('Nothing to change: %s', article)
            return False
    else:
        return False
Ejemplo n.º 19
0
def workon(page):
    mysite = pywikibot.getSite()
    try:
        text = page.get()
    except pywikibot.IsRedirectPage:
        pywikibot.output(u'%s is a redirect page. Skipping' %
                         page.title(asLink=True))
        return
    except pywikibot.NoPage:
        pywikibot.output(u'%s does not exist. Skipping' %
                         page.title(asLink=True))
        return
    pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" %
                     page.title())
    links = page.linkedPages()
    if len(links) > 0:
        pywikibot.getall(mysite, links)
    else:
        pywikibot.output('Nothing left to do.')
        return

    for page2 in links:
        try:
            target = page2.getRedirectTarget()
        except (pywikibot.Error, pywikibot.SectionError):
            continue
        text = treat(text, page2, target)
    if text != page.get():
        comment = pywikibot.translate(mysite, msg)
        pywikibot.showDiff(page.get(), text)
        try:
            page.put(text, comment)
        except (pywikibot.Error):
            pywikibot.output('Error: unable to put %s' %
                             page.title(asLink=True))
Ejemplo n.º 20
0
 def save(self, text, page, comment, minorEdit=False, botflag=False):
   # only save if something was changed
   if text != page.get():
     # Show the title of the page we're working on.
     # Highlight the title in purple.
     pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
                      % page.title())
     # show what was changed
     pywikibot.showDiff(page.get(), text)
     
     pywikibot.output(u'Comment: %s' %comment)
     choice = pywikibot.inputChoice(
       u'Do you want to accept these changes?',
       ['Yes', 'No'], ['y', 'N'], 'N')
     if choice == 'y':
       try:
           # Save the page
           page.put(text, comment=comment,
                    minorEdit=minorEdit, botflag=botflag)
       except pywikibot.LockedPage:
           pywikibot.output(u"Page %s is locked; skipping."
                            % page.title(asLink=True))
       except pywikibot.EditConflict:
           pywikibot.output(
               u'Skipping %s because of edit conflict'
               % (page.title()))
       except pywikibot.SpamfilterError, error:
           pywikibot.output(
               u'Cannot change %s because of spam blacklist entry %s'
               % (page.title(), error.url))
       else:
           return True
Ejemplo n.º 21
0
def addWeek(monday=None):
    '''
    Add another week to http://nl.wikipedia.org/wiki/Wikipedia:Te_verwijderen_categorie%C3%ABn
    '''
    page = wikipedia.Page(wikipedia.getSite(u'nl', u'wikipedia'),
                          u'Wikipedia:Te verwijderen categorieën')
    pagetext = page.get()
    #(year, week, Null) = monday.isocalendar()
    year = monday.strftime('%Y')
    week = monday.strftime('%W')
    qmonday = monday + timedelta(weeks=3)
    #(qyear, qweek, Null) = qmonday.isocalendar()
    qyear = qmonday.strftime('%Y')
    qweek = qmonday.strftime('%W')

    #Add the current week template
    pagetext = pagetext.replace(
        u'<!-- HIERVOOR -->',
        u'{{Wikipedia:Te verwijderen categorieën/Toegevoegd ' + str(year) +
        u' week ' + str(week) + u'}}\n<!-- HIERVOOR -->')
    #Remove the current week template from the queue
    pagetext = pagetext.replace(
        u'<!-- {{Wikipedia:Te verwijderen categorieën/Toegevoegd ' +
        str(year) + u' week ' + str(week) + u'}} -->\n', u'')
    #Add a new week template to the queue
    pagetext = pagetext.replace(
        u'<!-- EINDE QUEUE -->',
        u'<!-- {{Wikipedia:Te verwijderen categorieën/Toegevoegd ' +
        str(qyear) + u' week ' + str(qweek) + u'}} -->\n<!-- EINDE QUEUE -->')
    wikipedia.showDiff(page.get(), pagetext)
    page.put(
        pagetext, u'{{Wikipedia:Te verwijderen categorieën/Toegevoegd ' +
        str(year) + u' week ' + str(week) + u'}} erbij')
Ejemplo n.º 22
0
    def treat(self, page):
        # Show the title of the page we're working on.
        # Highlight the title in purple.
        wikipedia.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" % page.title())
        try:
            oldText = page.get()
            # Inside image maps, don't touch selflinks, as they're used
            # to create tooltip labels. See for example:
            # http://de.wikipedia.org/w/index.php?title=Innenstadt_%28Bautzen%29&diff=next&oldid=35721641
            if '<imagemap>' in oldText:
                wikipedia.output(u'Skipping page %s because it contains an image map.' % page.aslink())
                return
            text = oldText
            curpos = 0
            while curpos < len(text):
                match = self.linkR.search(text, pos = curpos)
                if not match:
                    break
                # Make sure that next time around we will not find this same hit.
                curpos = match.start() + 1
                text, jumpToBeginning = self.handleNextLink(page, text, match)
                if jumpToBeginning:
                    curpos = 0

            if oldText == text:
                wikipedia.output(u'No changes necessary.')
            else:
                wikipedia.showDiff(oldText, text)
                page.put_async(text)
        except wikipedia.NoPage:
            wikipedia.output(u"Page %s does not exist?!" % page.aslink())
        except wikipedia.IsRedirectPage:
            wikipedia.output(u"Page %s is a redirect; skipping." % page.aslink())
        except wikipedia.LockedPage:
            wikipedia.output(u"Page %s is locked?!" % page.aslink())
Ejemplo n.º 23
0
def processCategory(page):
    '''
    Process a single category
    '''
    templates = page.templatesWithParams()
    fields = {}
    for (template, params) in templates:
	if template==u'Air Force header':
	    for param in params:
		#Split at =
		(field, sep, value) = param.partition(u'=')
		if not value==u'':
		    fields[field]=value.strip()
    # Process a gallery at the US Air Force site
    if fields.get('id'):
	if fields.get('subject'):
	    target = fields.get('subject')
	else:
	    target = page.titleWithoutNamespace()
    
	processGallery(fields.get('id'), target)

	# Mark the category as done so we can skip it later on
	oldtext = page.get()
	newtext = re.sub(u'\{\{Air Force header', u'{{Air Force header\n|done=~~~~', oldtext)
	comment = u'Transfered all images from http://www.af.mil/photos/mediagallery.asp?id=' + fields.get('id') + u' to [[Category:' + target + u']]'
	wikipedia.showDiff(oldtext, newtext)
	page.put(newtext, comment)
Ejemplo n.º 24
0
def appendtext(page, apptext):
    global always
    if page.isRedirectPage():
        page = page.getRedirectTarget()
    if not page.exists():
        if page.isTalkPage():
            text = u''
        else:
            raise pywikibot.NoPage(u"Page '%s' does not exist" % page.title())
    else:
        text = page.get()
    # Here you can go editing. If you find you do not
    # want to edit this page, just return
    oldtext = text
    text += apptext
    if text != oldtext:
        pywikibot.showDiff(oldtext, text)
        if not always:
            choice = pywikibot.inputChoice(
                u'Do you want to accept these changes?', ['Yes', 'No', 'All'],
                ['y', 'N', 'a'], 'N')
            if choice == 'a':
                always = True
        if always or choice == 'y':
            page.put(text, pywikibot.translate(pywikibot.getSite(), comment))
Ejemplo n.º 25
0
def workon(page):
    mysite = pywikibot.getSite()
    try:
        text = page.get()
    except pywikibot.IsRedirectPage:
        pywikibot.output(u'%s is a redirect page. Skipping'
                         % page.title(asLink=True))
        return
    except pywikibot.NoPage:
        pywikibot.output(u'%s does not exist. Skipping'
                         % page.title(asLink=True))
        return
    pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
                     % page.title())
    links = page.linkedPages()
    if len(links) > 0:
        pywikibot.getall(mysite,links)
    else:
        pywikibot.output('Nothing left to do.')
        return

    for page2 in links:
        try:
            target = page2.getRedirectTarget()
        except (pywikibot.Error,pywikibot.SectionError):
            continue
        text = treat(text, page2, target)
    if text != page.get():
        comment = i18n.twtranslate(mysite, 'fixing_redirects-fixing')
        pywikibot.showDiff(page.get() ,text)
        try:
            page.put(text, comment)
        except (pywikibot.Error):
            pywikibot.output('Error: unable to put %s'
                             % page.title(asLink=True))
Ejemplo n.º 26
0
def workon(page):
    mysite = wikipedia.getSite()
    try:
        text = page.get()
    except wikipedia.IsRedirectPage:
        wikipedia.output(u'%s is a redirect page. Skipping' % page.aslink())
        return
    except wikipedia.NoPage:
        wikipedia.output(u'%s does not exist. Skipping' % page.aslink())
        return
    wikipedia.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" % page.title())
    links = page.linkedPages()
    if len(links) > 0:
        wikipedia.getall(mysite,links)
    else:
        wikipedia.output('Nothing left to do.')
        return
    
    for page2 in links:
        try:
            target = page2.getRedirectTarget()
        except (wikipedia.Error,wikipedia.SectionError):
            continue
        text = treat(text, page2, target)
    if text != page.get():
        comment = wikipedia.translate(mysite, msg)
        wikipedia.showDiff(page.get() ,text)
        try:
            page.put(text, comment)
        except (wikipedia.Error):
            wikipedia.output('Error: unable to put %s' % page.aslink())
Ejemplo n.º 27
0
    def convertAllHTMLTables(self, text):
        '''
        Converts all HTML tables in text to wiki syntax.
        Returns the converted text, the number of converted tables and the
        number of warnings that occured.
        '''
        text = self.markActiveTables(text)

        convertedTables = 0
        warningSum = 0
        warningMessages = u''

        while True:
            table, start, end = self.findTable(text)
            if not table:
                # no more HTML tables left
                break
            pywikibot.output(">> Table %i <<" % (convertedTables + 1))
            # convert the current table
            newTable, warningsThisTable, warnMsgsThisTable = self.convertTable(
                table)
            # show the changes for this table
            if not self.quietMode:
                pywikibot.showDiff(table.replace('##table##', 'table'),
                                   newTable)
            warningSum += warningsThisTable
            for msg in warnMsgsThisTable:
                warningMessages += 'In table %i: %s' % (convertedTables + 1,
                                                        msg)
            text = text[:start] + newTable + text[end:]
            convertedTables += 1

        pywikibot.output(warningMessages)
        return text, convertedTables, warningSum
Ejemplo n.º 28
0
def writeMainFreeUploads(subpages):
    site = wikipedia.getSite(u'en', u'wikipedia')
    page = wikipedia.Page(site, u'User:Multichill/Free_uploads')
    oldtext = page.get()
    text = u'__TOC__\n'
    #text = text + u'== Links to day pages ==\n'
    #text = text + u'{{Special:PrefixIndex/User:Multichill/Free uploads/20}}\n'
    text = text + u'== This week ==\n'

    i = 0
    limit = 7

    # From new to old
    subpages.reverse()

    for subpage in subpages:
	date = subpage.replace(u'User:Multichill/Free uploads/', u'')
	if i < limit:
            text = text + u'===[[%s|%s]]===\n' % (subpage, date)
            text = text + u'{{%s}}\n' % (subpage,)
        elif i == limit:
            text = text + u'== Older ==\n'
            text = text + u'* [[%s|%s]]\n' % (subpage, date)
        else:
            text = text + u'* [[%s|%s]]\n' % (subpage, date)

        i = i + 1

    comment = u'Updating list, %d subpages contain images' % (len(subpages),)
    wikipedia.showDiff(oldtext, text)
    wikipedia.output(comment)
    page.put(text, comment)
Ejemplo n.º 29
0
 def save(self, text, page, comment=None, **kwargs):
     # only save if something was changed
     if text != page.get():
         # Show the title of the page we're working on.
         # Highlight the title in purple.
         pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
                          % page.title())
         # show what was changed
         pywikibot.showDiff(page.get(), text)
         pywikibot.output(u'Comment: %s' % comment)
         choice = pywikibot.inputChoice(
             u'Do you want to accept these changes?',
             ['Yes', 'No'], ['y', 'N'], 'N')
         if choice == 'y':
             try:
                 # Save the page
                 page.put(text, comment=comment or self.comment, **kwargs)
             except pywikibot.LockedPage:
                 pywikibot.output(u"Page %s is locked; skipping."
                                  % page.title(asLink=True))
             except pywikibot.EditConflict:
                 pywikibot.output(
                     u'Skipping %s because of edit conflict'
                     % (page.title()))
             except pywikibot.SpamfilterError, error:
                 pywikibot.output(
                     u'Cannot change %s because of spam blacklist entry %s'
                     % (page.title(), error.url))
             else:
                 return True
Ejemplo n.º 30
0
 def put_page(self, page, new):
     """
     Prints diffs between orginal and new (text), puts new text for page
     """
     pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
                      % page.title())
     pywikibot.showDiff(page.get(), new)
     if not self.acceptall:
         choice = pywikibot.inputChoice(u'Do you want to accept ' +
                                        u'these changes?',
                                        ['Yes', 'No', 'All'],
                                        ['y', 'N', 'a'], 'N')
         if choice == 'a':
             self.acceptall = True
         if choice == 'y':
             page.put_async(new)
     if self.acceptall:
         try:
             page.put(new)
         except pywikibot.EditConflict:
             pywikibot.output(u'Skipping %s because of edit conflict'
                               % (page.title(),))
         except pywikibot.SpamfilterError, e:
             pywikibot.output(
                 u'Cannot change %s because of blacklist entry %s'
                 % (page.title(), e.url))
         except pywikibot.PageNotSaved, error:
             pywikibot.output(u'Error putting page: %s' % (error.args,))
Ejemplo n.º 31
0
def process_article(page, tag):
    EditMsg = "Robot: Tagging {{Film|%s}}" % tag
    wikipedia.setAction(EditMsg)
    try:
        wikitext = page.get()
    except wikipedia.NoPage:
        page.put("{{Film|%s}}" % tag)
        return
    except wikipedia.IsRedirectPage:
        return
    if re.search(tag, wikitext, re.I):
        print "Skipping " + str(page)
        return
    # Fix Casing (Reduces the number of possible expressions)
    wikitext = re.compile(r'\{\{\s*(template:|)film',
                          re.IGNORECASE).sub(r'{{Film', wikitext)
    state0 = wikitext

    # Add tf parameter
    wikitext = re.compile(r'\{\{\s*film(.*?)\}\}',
                          re.IGNORECASE).sub(r'{{Film\1|%s}}' % tag, wikitext)

    wikipedia.showDiff(state0, wikitext)

    if (wikitext != state0):
        try:
            print 'Going to edit %s' % str(page)
            wikipedia.output(u'WRITE:	Adding %s bytes.' %
                             str(len(wikitext) - len(state0)))
            page.put(wikitext)
        except KeyboardInterrupt:
            sys.exit()
Ejemplo n.º 32
0
def process_article(page, tag):
		EditMsg = "Robot: Tagging {{Film|%s}}" %tag
		wikipedia.setAction(EditMsg)
		try:
			wikitext = page.get()
		except wikipedia.NoPage:
			page.put("{{Film|%s}}" %tag)
			return
		except wikipedia.IsRedirectPage:
			return
		if re.search(tag,wikitext,re.I):
			print "Skipping " + str(page)
			return
		# Fix Casing (Reduces the number of possible expressions)
		wikitext = re.compile(r'\{\{\s*(template:|)film', re.IGNORECASE).sub(r'{{Film', wikitext)
		state0 = wikitext
 
		# Add tf parameter
		wikitext = re.compile(r'\{\{\s*film(.*?)\}\}', re.IGNORECASE).sub(r'{{Film\1|%s}}' %tag, wikitext)
 
		wikipedia.showDiff(state0, wikitext)
 
		if (wikitext != state0):
			try:
				print 'Going to edit %s' %str(page)
				wikipedia.output(u'WRITE:	Adding %s bytes.' % str(len(wikitext)-len(state0)))
				page.put(wikitext)	
			except KeyboardInterrupt:
				sys.exit()
def sort_by_country_subcat(subcat, subject):
    print subcat
    subcat = subcat.replace("_", " ")
    subject = subject.replace("_", " ")
    if subcat.startswith(subject):
        temp1 = subcat[len(subject) :].lstrip()
        if temp1.startswith("from"):
            temp2 = temp1[len("from") :].lstrip()
        elif temp1.startswith("of"):
            temp2 = temp1[len("of") :].lstrip()
        elif temp1.startswith("in"):
            temp2 = temp1[len("in") :].lstrip()
        else:
            temp2 = ""
        if temp2:
            if temp2.startswith("the"):
                country = temp2[len("the") :].lstrip()
            else:
                country = temp2
            page = wikipedia.Page(wikipedia.getSite(), "Category:" + subcat)
            old = u"\[\[[cC]ategory:" + subject + u" by country[^\]]*\]\]"
            new = u"[[Category:" + subject + u" by country|" + country + u"]]"
            comment = u"Sorting [[:Category:" + subject + u" by country]]"
            newtext = wikipedia.replaceExcept(page.get(), old, new, [])
            wikipedia.showDiff(page.get(), newtext)
            page.put(newtext, comment)
Ejemplo n.º 34
0
def addTopicCategory(page, conn, cursor):
    wikipedia.output(u'Working on: %s' % page.title())
    
    templates = page.templates()
    if not u'Rijksmonument' in page.templates():
	wikipedia.output(u'Rijksmonument template not found at: %s' % page.title())
	return False

    rijksmonumentid=-1
    
    for (template, params) in page.templatesWithParams():
	if template==u'Rijksmonument':
	    if len(params)==1:
		try:
		    rijksmonumentid = int(params[0])
		except ValueError:
		    wikipedia.output(u'Unable to extract a valid id')
		break

    if (rijksmonumentid < 0 or 600000 < rijksmonumentid ):
	wikipedia.output(u'Invalid id')
	return False
		
    oorspr_functie = getOorspronkelijkeFunctie(rijksmonumentid, conn, cursor)
    if not oorspr_functie:
	wikipedia.output(u'No oorspr_functie found')
	return False

    oldtext = page.get()
    newtext = oldtext + u'{{subst:Rijksmonument category|%s|subst=subst:}}' % (oorspr_functie,)
    
    comment = u'Adding [[Template:Rijksmonument category|"%s" category]] based on Rijksmonument identifier' % (oorspr_functie,)
    wikipedia.showDiff(oldtext, newtext)
    page.put(newtext, comment)
Ejemplo n.º 35
0
    def save(self, page, text):
        if text != page.get():
            # Show the title of the page we're working on.
            # Highlight the title in purple.
            pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
                             % page.title())
            pywikibot.showDiff(page.get(), text)
            if not self.always:
                choice = pywikibot.inputChoice(
                    u'Do you want to accept these changes?',
                    ['Yes', 'No', 'Always yes'], ['y', 'N', 'a'], 'N')
                if choice == 'n':
                    return
                elif choice == 'a':
                    self.always = True

            if self.always:
                try:
                    page.put(text, comment=self.comment)
                except pywikibot.EditConflict:
                    pywikibot.output(u'Skipping %s because of edit conflict'
                                     % (page.title(),))
                except pywikibot.SpamfilterError, e:
                    pywikibot.output(
                        u'Cannot change %s because of blacklist entry %s'
                        % (page.title(), e.url))
                except pywikibot.LockedPage:
                    pywikibot.output(u'Skipping %s (locked page)'
                                     % (page.title(),))
Ejemplo n.º 36
0
    def save(self, page, newText):
        """
        Saves the page to the wiki, if the user accepts the changes made.
        """
        pywikibot.showDiff(page.get(), newText)
        if not self.always:
            choice = pywikibot.inputChoice(
                u'Do you want to accept these changes?',
                ['Yes', 'No', 'Always yes'], ['y', 'N', 'a'], 'Y')
            if choice == 'n':
                return
            elif choice == 'a':
                self.always = True

        if self.always:
            try:
                page.put(newText)
            except pywikibot.EditConflict:
                pywikibot.output(u'Skipping %s because of edit conflict'
                                 % (page.title(),))
            except pywikibot.SpamfilterError, e:
                pywikibot.output(
                    u'Cannot change %s because of blacklist entry %s'
                    % (page.title(), e.url))
            except pywikibot.LockedPage:
                pywikibot.output(u'Skipping %s (locked page)' % (page.title(),))
Ejemplo n.º 37
0
def convertList(page):
    '''
    Convert a list of NRHP entries. Both headers and items will be converted.
    '''
    wikipedia.output(u'Working on %s' % page.title())

    text = page.get()
    try:
        newtext = convertHeaders(page, text)
        newtext = convertItems(page, newtext)
    except TypeError or AttributeError:
        wikipedia.output(
            u'One of the regexes failed at %s, skipping this page' %
            (page.title, ))
        traceback.print_exc(file=sys.stdout)
        time.sleep(10)
        return u'Failed'

    if not text == newtext:
        wikipedia.showDiff(text, newtext)

        comment = u'Converting list to use [[Template:NRHP header]] and [[Template:NRHP row]]'

        #choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['Yes', 'No'], ['y', 'n'], 'n')
        choice = 'y'

        if choice == 'y':
            #DEBUG
            page.put(newtext, comment)
            return u'Success'
            #wikipedia.output(newtext)

    return u'Unchanged'
Ejemplo n.º 38
0
def processCategory(page):
    '''
    Process a single category
    '''
    templates = page.templatesWithParams()
    fields = {}
    for (template, params) in templates:
        if template == u'Air Force header':
            for param in params:
                #Split at =
                (field, sep, value) = param.partition(u'=')
                if not value == u'':
                    fields[field] = value.strip()
    # Process a gallery at the US Air Force site
    if fields.get('id'):
        if fields.get('subject'):
            target = fields.get('subject')
        else:
            target = page.titleWithoutNamespace()

        processGallery(fields.get('id'), target)

        # Mark the category as done so we can skip it later on
        oldtext = page.get()
        newtext = re.sub(u'\{\{Air Force header',
                         u'{{Air Force header\n|done=~~~~', oldtext)
        comment = u'Transfered all images from http://www.af.mil/photos/mediagallery.asp?id=' + fields.get(
            'id') + u' to [[Category:' + target + u']]'
        wikipedia.showDiff(oldtext, newtext)
        page.put(newtext, comment)
Ejemplo n.º 39
0
def appendtext(page, apptext):
    global always
    if page.isRedirectPage():
        page = page.getRedirectTarget()
    if not page.exists():
        if page.isTalkPage():
            text = u''
        else:
            raise pywikibot.NoPage(u"Page '%s' does not exist" % page.title())
    else:
        text = page.get()
    # Here you can go editing. If you find you do not
    # want to edit this page, just return
    oldtext = text
    text += apptext
    if text != oldtext:
        pywikibot.showDiff(oldtext, text)
        if not always:
            choice = pywikibot.inputChoice(
                u'Do you want to accept these changes?', ['Yes', 'No', 'All'],
                ['y', 'N', 'a'], 'N')
            if choice == 'a':
                always = True
        if always or choice == 'y':
            page.put(text, pywikibot.translate(pywikibot.getSite(), comment))
Ejemplo n.º 40
0
    def convertAllHTMLTables(self, text):
        """
        Converts all HTML tables in text to wiki syntax.
        Returns the converted text, the number of converted tables and the
        number of warnings that occured.
        """
        text = self.markActiveTables(text)

        convertedTables = 0
        warningSum = 0
        warningMessages = u""

        while True:
            table, start, end = self.findTable(text)
            if not table:
                # no more HTML tables left
                break
            wikipedia.output(">> Table %i <<" % (convertedTables + 1))
            # convert the current table
            newTable, warningsThisTable, warnMsgsThisTable = self.convertTable(table)
            # show the changes for this table
            if not self.quietMode:
                wikipedia.showDiff(table.replace("##table##", "table"), newTable)
            warningSum += warningsThisTable
            for msg in warnMsgsThisTable:
                warningMessages += "In table %i: %s" % (convertedTables + 1, msg)
            text = text[:start] + newTable + text[end:]
            convertedTables += 1

        wikipedia.output(warningMessages)

        return text, convertedTables, warningSum
Ejemplo n.º 41
0
    def save(self, page, newText):
        """
        Saves the page to the wiki, if the user accepts the changes made.
        """
        pywikibot.showDiff(page.get(), newText)
        if not self.always:
            choice = pywikibot.inputChoice(
                u'Do you want to accept these changes?',
                ['Yes', 'No', 'Always yes'], ['y', 'N', 'a'], 'Y')
            if choice == 'n':
                return
            elif choice == 'a':
                self.always = True

        if self.always:
            try:
                page.put(newText)
            except pywikibot.EditConflict:
                pywikibot.output(u'Skipping %s because of edit conflict'
                                 % (page.title(),))
            except pywikibot.SpamfilterError, e:
                pywikibot.output(
                    u'Cannot change %s because of blacklist entry %s'
                    % (page.title(), e.url))
            except pywikibot.LockedPage:
                pywikibot.output(u'Skipping %s (locked page)' % (page.title(),))
Ejemplo n.º 42
0
    def treat(self, page):
        # Show the title of the page we're working on.
        # Highlight the title in purple.
        wikipedia.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" % page.title())
        try:
            oldText = page.get()
            text = oldText
            curpos = 0
            while curpos < len(text):
                match = self.linkR.search(text, pos = curpos)
                if not match:
                    break
                # Make sure that next time around we will not find this same hit.
                curpos = match.start() + 1
                text, jumpToBeginning = self.handleNextLink(text, match)
                if jumpToBeginning:
                    curpos = 0

            if oldText == text:
                wikipedia.output(u'No changes necessary.')
            else:
                wikipedia.showDiff(oldText, text)
                page.put(text)
        except wikipedia.NoPage:
            wikipedia.output(u"Page %s does not exist?!" % page.aslink())
        except wikipedia.IsRedirectPage:
            wikipedia.output(u"Page %s is a redirect; skipping." % page.aslink())
        except wikipedia.LockedPage:
            wikipedia.output(u"Page %s is locked?!" % page.aslink())
Ejemplo n.º 43
0
def tagNowCommons(wImage, cImage, timestamp):
    site = wikipedia.getSite()
    language = site.language()
    family = site.family.name

    imagepage = wikipedia.ImagePage(wikipedia.getSite(), wImage)
    if not imagepage.exists() or imagepage.isRedirectPage():
        return

    if skips.get(family) and skips.get(family).get(language):
        localskips = skips.get(family).get(language)
    else:
        localskips = skips.get('_default')

    for template in imagepage.templates():
        title = template.replace(u'_', u' ').strip()
        if title in localskips:
            return
    text = imagepage.get()
    oldtext = text

    text = u'{{NowCommons|File:%s|date=%s|bot=~~~}}\n' % (cImage.replace(
        u'_', u' '), timestamp) + text
    comment = u'File is available on Wikimedia Commons.'
    wikipedia.showDiff(oldtext, text)
    try:
        imagepage.put(text, comment)
        #print u'put'
    except wikipedia.LockedPage:
        return
Ejemplo n.º 44
0
def tagNowCommons(wImage, cImage, timestamp):
    site = wikipedia.getSite()
    language = site.language()
    family = site.family.name

    imagepage = wikipedia.ImagePage(wikipedia.getSite(), wImage)
    if not imagepage.exists() or imagepage.isRedirectPage():
	return

    if skips.get(family) and skips.get(family).get(language):
	localskips = skips.get(family).get(language)
    else:
	localskips = skips.get('_default')

    for template in imagepage.templates():
	title = template.replace(u'_', u' ').strip()
	if title in localskips:
	    return
    text = imagepage.get()
    oldtext = text

    text = u'{{NowCommons|File:%s|date=%s|bot=~~~}}\n' % (cImage.replace(u'_', u' '), timestamp) + text
    comment = u'File is available on Wikimedia Commons.'
    wikipedia.showDiff(oldtext, text)
    try:
	imagepage.put(text, comment)
	#print u'put'
    except wikipedia.LockedPage:
	return
Ejemplo n.º 45
0
    def save(self, page, text):
        if text != page.get():
            # Show the title of the page we're working on.
            # Highlight the title in purple.
            pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" %
                             page.title())
            pywikibot.showDiff(page.get(), text)
            if not self.always:
                choice = pywikibot.inputChoice(
                    u'Do you want to accept these changes?',
                    ['Yes', 'No', 'Always yes'], ['y', 'N', 'a'], 'N')
                if choice == 'n':
                    return
                elif choice == 'a':
                    self.always = True

            if self.always:
                try:
                    page.put(text, comment=self.comment)
                except pywikibot.EditConflict:
                    pywikibot.output(u'Skipping %s because of edit conflict' %
                                     (page.title(), ))
                except pywikibot.SpamfilterError, e:
                    pywikibot.output(
                        u'Cannot change %s because of blacklist entry %s' %
                        (page.title(), e.url))
                except pywikibot.LockedPage:
                    pywikibot.output(u'Skipping %s (locked page)' %
                                     (page.title(), ))
Ejemplo n.º 46
0
    def tagNowcommons(self, imagepage, filename):
        """ Tagged the imag which has been moved to Commons for deletion. """
        if pywikibot.Page(pywikibot.getSite('commons', 'commons'),
                          u'File:' + filename).exists():
            # Get a fresh copy, force to get the page so we dont run into edit
            # conflicts
            imtxt = imagepage.get(force=True)

            # Remove the move to commons templates
            if imagepage.site().language() in moveToCommonsTemplate:
                for moveTemplate in moveToCommonsTemplate[imagepage.site().language()]:
                    imtxt = re.sub(u'(?i)\{\{' + moveTemplate +
                                   u'[^\}]*\}\}', u'', imtxt)

            # add {{NowCommons}}
            if imagepage.site().language() in nowCommonsTemplate:
                addTemplate = nowCommonsTemplate[
                    imagepage.site().language()] % filename
            else:
                addTemplate = nowCommonsTemplate['_default'] % filename

            commentText = i18n.twtranslate(
                imagepage.site(), 'commons-file-now-available',
                {'localfile': imagepage.title(withNamespace=False),
                 'commonsfile': filename})

            pywikibot.showDiff(imagepage.get(), imtxt + addTemplate)
            imagepage.put(imtxt + addTemplate, comment=commentText)
def tagUncategorized(templateTitle):
    site = wikipedia.getSite()
    language = site.language()
    family = site.family.name

    page = wikipedia.Page(wikipedia.getSite(), u'Template:%s' % (templateTitle,))

    if not page.exists() or page.isRedirectPage():
	return False

    text = page.get()
    oldtext = text

    text = text + u'<noinclude>\n\n%s\n</noinclude>' % (uncategorizedTemplate.get(family).get(language), )

    wikipedia.showDiff(oldtext, text)
    try:
        wikipedia.output(page.title())
	page.put(text, editComment.get(family).get(language), maxTries=1)
    except wikipedia.LockedPage:
	return
    except wikipedia.MaxTriesExceededError:
	return
    except wikipedia.EditConflict:
	return
Ejemplo n.º 48
0
    def put_page(self, page, new):
        """ Prints diffs between orginal and new (text), puts new text for page

        """
        pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" %
                         page.title())
        pywikibot.showDiff(page.get(), new)
        if not self.acceptall:
            choice = pywikibot.inputChoice(
                u'Do you want to accept ' + u'these changes?',
                ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
            if choice == 'a':
                self.acceptall = True
            if choice == 'y':
                page.put_async(new, self.msg)
        if self.acceptall:
            try:
                page.put(new, self.msg)
            except pywikibot.EditConflict:
                pywikibot.output(u'Skipping %s because of edit conflict' %
                                 page.title())
            except pywikibot.SpamfilterError, e:
                pywikibot.output(
                    u'Cannot change %s because of blacklist entry %s' %
                    (page.title(), e.url))
            except pywikibot.PageNotSaved, error:
                pywikibot.error(u'putting page: %s' % error.args)
Ejemplo n.º 49
0
    def updateInterwiki(self, wikipediaPage=None, commonsPage=None):
        '''
        Update the interwiki's at commons from a wikipedia page. The bot just
        replaces the interwiki links at the commons page with the interwiki's from
        the wikipedia page. This should probably be more intelligent. We could use
        add all the interwiki's and remove duplicates. Or only remove language links
        if multiple language links to the same language exist.

        This function is disabled for the moment untill i figure out what the best
        way is to update the interwiki's.
        '''
        interwikis = {}
        comment = u''
        interwikilist = wikipediaPage.interwiki()
        interwikilist.append(wikipediaPage)

        for interwikiPage in interwikilist:
            interwikis[interwikiPage.site()] = interwikiPage
        oldtext = commonsPage.get()
        # The commonssite object doesnt work with interwiki's
        newtext = pywikibot.replaceLanguageLinks(oldtext, interwikis,
                                                 pywikibot.getSite(u'nl'))
        comment = u'Updating interwiki\'s from [[' + \
                  wikipediaPage.site().language()  + \
                  u':' + wikipediaPage.title() + u']]'

        if newtext != oldtext:
            #This doesnt seem to work. Newtext has some trailing whitespace
            pywikibot.showDiff(oldtext, newtext)
            commonsPage.put(newtext=newtext, comment=comment)
Ejemplo n.º 50
0
def createredir(origname):
	site = wikipedia.getSite()
	redircontent = re.sub('OH', 'Ohio', origname)
	redircontent = '#REDIRECT [[%s]]' %(redircontent)
	page = wikipedia.Page(site, origname)
	print page
	wikipedia.showDiff('', redircontent)
	page.put(redircontent, 'Creating redirect per [[WP:BOTREQ#Need_some_redlinks_to_become_redirects|BOTREQ]]')
Ejemplo n.º 51
0
def changeCommonscat (page = None, oldtemplate = u'', oldcat = u'', newtemplate = u'', newcat = u''):
    '''
    Change the current commonscat template and target. 
    '''
    newtext = re.sub(u'(?i)\{\{' + oldtemplate + u'\|?[^}]*\}\}',  u'{{' + newtemplate + u'|' + newcat + u'}}', page.get())
    comment = u'Changing commonscat link from [[:Commons:Category:' + oldcat + u'|' + oldcat + u']] to [[:Commons:Category:' + newcat + u'|' + newcat + u']]'
    wikipedia.showDiff(page.get(), newtext)
    page.put(newtext, comment)
Ejemplo n.º 52
0
def main():
    pagesDict = {
        'Template:Weather_World_C/Auto':
        "http://tools.wikimedia.de/~skenmy/wnweather/overlays/%d%b%y-%H-C-world",
        'Template:Weather_World_F/Auto':
        "http://tools.wikimedia.de/~skenmy/wnweather/overlays/%d%b%y-%H-F-world",
    }
    args = wikipedia.handleArgs()
    all = False
    for currentArgument in args:
        if currentArgument.startswith("-always"):
            all = True

    for pageName in pagesDict:
        formatUrl = pagesDict[pageName]
        now = datetime.datetime.utcnow()
        urlo = now.strftime(formatUrl)
        wikipedia.output(u'Prendo la pagina dal server...')
        try:
            htmlText = pageText(urlo)
        except urllib2.HTTPError:
            try:
                wikipedia.output(
                    u"Errore del server. Aspetto 10 secondi... " +
                    time.strftime("%d %b %Y %H:%M:%S (UTC)", time.gmtime()))
                time.sleep(10)
                htmlText = pageText(urlo)
            except urllib2.HTTPError:
                wikipedia.output(u"Errore del server. Chiudo.")
                return

        htmlText = re.sub("Wikinews Weather Service",
                          "Servizio Meteo di Wikinotizie", htmlText)
        htmlText = re.sub("World Map", r"Mondo", htmlText)
        htmlText = re.sub(
            "''\d{2}:\d{2} UTC .*? .*? .*?''</span>",
            "''{{subst:LOCALDAY}} {{subst:LOCALMONTHNAME}} {{subst:LOCALYEAR}}, {{subst:LOCALHOUR}}:00 [[w:CET|<span style=\"color:white; text-decoration:underline;\">CET</span>]] ({{subst:CURRENTHOUR}}:00 [[w:UTC|<span style=\"color:white; text-decoration:underline;\">UTC</span>]])''</span>",
            htmlText)

        page = wikipedia.Page(wikipedia.getSite(code='it', fam='wikinews'),
                              pageName)
        if page.exists():
            oldtext = page.get()
        else:
            oldtext = ""
        wikipedia.showDiff(oldtext, htmlText)

        if not all:
            choice = wikipedia.inputChoice(u"Modificare?",
                                           ['Yes', 'No', 'All'],
                                           ['y', 'N', 'a'], 'N')
        else:
            choice = 'y'
        if choice in ['A', 'a']:
            all = True
            choice = 'y'
        if choice in ['Y', 'y']:
            page.put(htmlText, u"Bot: Aggiorno il meteo")
Ejemplo n.º 53
0
def categoriesChecked(category):
    page = wikipedia.Page(wikipedia.getSite(), category)
    if (page.exists()):
        old = u'\{\{UncategorizedHeader([^\}]*)\}\}'
        new = u'{{UncategorizedHeader\\1|galleries=~~~~}}'
        newtext = wikipedia.replaceExcept(page.get(), old, new, [])
        comment = u'No more images in galleries'
        wikipedia.showDiff(page.get(), newtext)
        page.put(newtext, comment)
Ejemplo n.º 54
0
def main():
    args = wikipedia.handleArgs()
    all = False
    for currentArgument in args:
        if currentArgument.startswith("-always"):
            all = True
            
    templateFile = codecs.open("modello_wikinews_oil.txt", "r", "utf-8")
    modelloVoce = templateFile.read() # Legge il modello della pagina
    templateFile.close()
    
    now = datetime.datetime.utcnow()
    urlo = "http://www.nymex.com/index.aspx"
    wikipedia.output(u'Prendo la pagina dal server...')
    try:
        htmlText = pageText(urlo)
    except urllib2.HTTPError:
        try:
            wikipedia.output(u"Errore del server. Aspetto 10 secondi... " + time.strftime("%d %b %Y %H:%M:%S (UTC)", time.gmtime()) )
            time.sleep(10)
            htmlText = pageText(urlo)
        except urllib2.HTTPError:
            wikipedia.output(u"Errore del server. Chiudo.")
            return
    
    prezzoCL = re.search("<span id=\"LastCL\".*?>(.*?)</span>", htmlText).group(1)
    changeCL = re.search("<span id=\"ChangeCL\".*?>(<font.*?>)?(.*?)(</font>)?</span>", htmlText).group(2)
    
    prezzoBZ = re.search("<span id=\"LastBZ\".*?>(.*?)</span>", htmlText).group(1)
    changeBZ = re.search("<span id=\"ChangeBZ\".*?>(<font.*?>)?(.*?)(</font>)?</span>", htmlText).group(2)
    
    elencoSostituzioni = { # Sostituisce le variabili nel modello
        '#CL_curr': prezzoCL,
        '#CL_diff': changeCL,
                
        '#BZ_curr': prezzoBZ,
        '#BZ_diff': changeBZ,
    }
    
    nuovoTesto = massiveReplace(elencoSostituzioni, modelloVoce)
    #nuovoTesto = re.sub('\|- - - -', '|N.D.', nuovoTesto) # Per quando i dati non sono disponibili
    
    page = wikipedia.Page(wikipedia.getSite(code='it', fam='wikinews'), "Template:Dati petrolio/Auto")
    if page.exists():
        oldtext = page.get()
    else:
        oldtext = ""
    wikipedia.showDiff(oldtext, nuovoTesto)
    if not all:
        choice = wikipedia.inputChoice(u"Modificare?",  ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
    else:
        choice = 'y'
    if choice in ['A', 'a']:
        all = True
        choice = 'y'
    if choice in ['Y', 'y']:
        page.put(nuovoTesto, u"Bot: Aggiorno prezzi petrolio")
Ejemplo n.º 55
0
def main():
    args = wikipedia.handleArgs()
    all = False
    for currentArgument in args:
        if currentArgument.startswith("-always"):
            all = True
            
    templateFile = codecs.open("modello_palinsesto.txt", "r", "utf-8")
    modelloVoce = templateFile.read() # Legge il modello della pagina
    templateFile.close()
    
    now = datetime.datetime.utcnow()
    fasceOrarie = ['mattina', 'pomeriggio', 'sera']
    pagineHtml = {}
    elencoSostituzioni = {}
    urlBase = "http://city.corriere.it/tv/tv.php?fascia="
    for i in fasceOrarie:
        urlo = urlBase + i
        print urlo
        wikipedia.output(u'Prendo la pagina dal server...')
        try:
            pagineHtml[i] = pageText(urlo)
        except urllib2.HTTPError:
            try:
                wikipedia.output(u"Errore del server. Aspetto 10 secondi... " + time.strftime("%d %b %Y %H:%M:%S (UTC)", time.gmtime()) )
                time.sleep(10)
                pagineHtml[i] = pageText(urlo)
            except urllib2.HTTPError:
                wikipedia.output(u"Errore del server. Chiudo.")
                return
                
        elencoSostituzioni['#rai1-' + i] = getProgramList('RAI 1', pagineHtml[i])
        elencoSostituzioni['#rai2-' + i] = getProgramList('RAI 2', pagineHtml[i])
        elencoSostituzioni['#rai3-' + i] = getProgramList('RAI 3', pagineHtml[i])
        elencoSostituzioni['#rete4-' + i] = getProgramList('RETE 4', pagineHtml[i])
        elencoSostituzioni['#canale5-' + i] = getProgramList('CANALE 5', pagineHtml[i])
        elencoSostituzioni['#italia1-' + i] = getProgramList('ITALIA 1', pagineHtml[i])
        elencoSostituzioni['#la7-' + i] = getProgramList('LA7', pagineHtml[i])
    
    
    nuovoTesto = massiveReplace(elencoSostituzioni, modelloVoce)
    
    page = wikipedia.Page(wikipedia.getSite(code='it', fam='wikinews'), "Template:ProgrammiTV")
    if page.exists():
        oldtext = page.get()
    else:
        oldtext = ""
    wikipedia.showDiff(oldtext, nuovoTesto)
    if not all:
        choice = wikipedia.inputChoice(u"Modificare?",  ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
    else:
        choice = 'y'
    if choice in ['A', 'a']:
        all = True
        choice = 'y'
    if choice in ['Y', 'y']:
        page.put(nuovoTesto, u"Bot: Aggiorno palinsesto TV")
Ejemplo n.º 56
0
    def categories(self):
        for page in self.generator:
            try:
                wikipedia.output(u'\n>>>> %s <<<<' % page.title())
                getCommons = wikipedia.getSite('commons', 'commons')
                commonsCategory = catlib.Category(getCommons,
                                                  'Category:%s' % page.title())
                try:
                    getcommonscat = commonsCategory.get(get_redirect=True)
                    commonsCategoryTitle = commonsCategory.title()
                    categoryname = commonsCategoryTitle.split('Category:',
                                                              1)[1]
                    if page.title() == categoryname:
                        oldText = page.get()
                        text = oldText

                        # for commonscat template
                        findTemplate = re.compile(ur'\{\{[Cc]ommons')
                        s = findTemplate.search(text)
                        findTemplate2 = re.compile(ur'\{\{[Ss]isterlinks')
                        s2 = findTemplate2.search(text)
                        if s or s2:
                            wikipedia.output(u'** Already done.')
                        else:
                            text = wikipedia.replaceCategoryLinks(
                                text + u'{{commonscat|%s}}' % categoryname,
                                page.categories())
                            if oldText != text:
                                wikipedia.showDiff(oldText, text)
                                if not self.acceptall:
                                    choice = wikipedia.inputChoice(
                                        u'Do you want to accept these changes?',
                                        ['Yes', 'No', 'All'], ['y', 'N', 'a'],
                                        'N')
                                    if choice == 'a':
                                        self.acceptall = True
                                if self.acceptall or choice == 'y':
                                    try:
                                        msg = wikipedia.translate(
                                            wikipedia.getSite(), comment2)
                                        page.put(text, msg)
                                    except wikipedia.EditConflict:
                                        wikipedia.output(
                                            u'Skipping %s because of edit conflict'
                                            % (page.title()))

                except wikipedia.NoPage:
                    wikipedia.output(u'Category does not exist in Commons!')

            except wikipedia.NoPage:
                wikipedia.output(u'Page %s does not exist?!' % page.title())
            except wikipedia.IsRedirectPage:
                wikipedia.output(u'Page %s is a redirect; skipping.' %
                                 page.title())
            except wikipedia.LockedPage:
                wikipedia.output(u'Page %s is locked?!' % page.title())
Ejemplo n.º 57
0
 def run(self):
     hints, removeHints = self.warnfileReader.getHints()
     k = hints.keys()
     k.sort()
     print "Fixing... %i pages" % len(k)
     for page in k:
         old = {}
         try:
             for page2 in page.interwiki():
                 old[page2.site()] = page2
         except wikipedia.IsRedirectPage:
             wikipedia.output(u"%s is a redirect page; not changing" %
                              page.aslink())
             continue
         except wikipedia.NoPage:
             wikipedia.output(u"Page %s not found; skipping" %
                              page.aslink())
             continue
         new = {}
         new.update(old)
         if page in hints:
             for page2 in hints[page]:
                 site = page2.site()
                 new[site] = page2
         if page in removeHints:
             for page2 in removeHints[page]:
                 site = page2.site()
                 try:
                     del new[site]
                 except KeyError:
                     pass
         mods, adding, removing, modifying = interwiki.compareLanguages(
             old, new, insite=page.site())
         if mods:
             wikipedia.output(page.aslink() + mods)
             oldtext = page.get()
             newtext = wikipedia.replaceLanguageLinks(oldtext, new)
             if 1:
                 wikipedia.showDiff(oldtext, newtext)
                 try:
                     status, reason, data = page.put(newtext,
                                                     comment='warnfile ' +
                                                     mods)
                 except wikipedia.LockedPage:
                     wikipedia.output(u"Page is locked. Skipping.")
                     continue
                 except wikipedia.SpamfilterError, e:
                     wikipedia.output(
                         u'Cannot change %s because of blacklist entry %s' %
                         (page.title(), e.url))
                     continue
                 except wikipedia.Error:
                     wikipedia.output(u"Error while saving page.")
                     continue
                 if str(status) != '302':
                     print status, reason