def treat(self, photo):
        duplicates = photo.findDuplicateImages()
        if duplicates:
            pywikibot.output(u"Skipping duplicate of %r" % duplicates)
            return duplicates[0]

        if self.subst:
            photo.metadata['subst'] = 'subst:'

        title = make_title(photo.metadata, self.front_titlefmt,
                           self.rear_titlefmt, self.variable_titlefmt)

        description = textlib.glue_template_and_params((self.pagefmt,
                                                        photo.metadata))

        bot = UploadRobot(url=photo.URL,
                          description=description,
                          useFilename=title,
                          keepFilename=True,
                          verifyDescription=self.verifyDescription,
                          uploadByUrl=False,
                          targetSite=self.site)
        bot._contents = photo.downloadPhoto().getvalue()
        bot._retrieved = True

        print title
        print description
        bot.run()

        return title
Example #2
0
    def write_dict_as_wiki(aDict, name, directory, template):
        """Write a given dictionary on disk, in template alignment format."""
        filename = os.path.join(directory, name.replace("/", ""))
        with codecs.open(filename, 'w', 'utf-8') as wikipage:
            wikipage.write("""\
{| class='wikitable' border='1'
|-
! Item
! Count
! Tag
! Categories
""")
            items = aDict.items()
            items.sort(key=lambda x: x[1], reverse=True)
            for item in items:
                try:
                    values = (template,
                              {'item': item[0], 'count': item[1],
                               'value': "", 'categories': ""})
                    table_line = ('\n' +
                                  textlib.glue_template_and_params(values))
                    wikipage.write(unicode(table_line))
                except:
                    pass
            wikipage.write("\n|}")
 def _debug_description(self, photo):
     """Print the description for debugging."""
     title = make_title(photo.metadata, self.front_titlefmt,
                        self.rear_titlefmt, self.variable_titlefmt)
     if self.subst:
         photo.metadata['subst'] = 'subst:'
     description = textlib.glue_template_and_params((self.pagefmt,
                                                     photo.metadata))
     print "= %s =" % title
     print "{{collapse|title=%s|1=<pre>\n%s\n</pre>}}" % (title,
                                                          description)
     print description
Example #4
0
 def write_dict_as_wiki(self, aDict, name, directory):
     """Write a given dictionary on disk, in template alignment format."""
     with codecs.open(os.path.join(directory, name), 'w', 'utf-8') as wikipage:
         wikipage.write("{|\nItem | Count | Tag | Categories")
         items = aDict.items()
         items.sort(key=lambda x: x[1], reverse=True)
         for item in items:
             values = (self.alignment_config_items['alignment_template'],
                       {'item': item[0], 'count': item[1],
                        'value': "", 'categories': ""})
             table_line = '\n' + textlib.glue_template_and_params(values)
             wikipage.write(unicode(table_line))
         wikipage.write("\n|}")
Example #5
0
 def write_dict_as_wiki(self, aDict, name, directory):
     """Write a given dictionary on disk, in template alignment format."""
     with codecs.open(os.path.join(directory, name), 'w',
                      'utf-8') as wikipage:
         wikipage.write("{|\nItem | Count | Tag | Categories")
         items = aDict.items()
         items.sort(key=lambda x: x[1], reverse=True)
         for item in items:
             values = (self.alignment_config_items['alignment_template'], {
                 'item': item[0],
                 'count': item[1],
                 'value': "",
                 'categories': ""
             })
             table_line = '\n' + textlib.glue_template_and_params(values)
             wikipage.write(unicode(table_line))
         wikipage.write("\n|}")
Example #6
0
def write_counter_as_wiki(counter, fh, template):
    """Write a given dictionary on disk, in template alignment format."""
    fh.write("""\
{| class='wikitable' border='1'
|-
! Item
! Count
! Tag
! Categories
""")
    for name, count in counter.most_common():
        values = (template,
                {'item': name, 'count': count,
                'value': "", 'categories': ""})
        table_line = ('\n' + textlib.glue_template_and_params(values))
        fh.write(unicode(table_line))
    fh.write("\n|}")
Example #7
0
    def _doUpload(self, photo):
        duplicates = photo.findDuplicateImages(self.site)
        if duplicates:
            pywikibot.output(u"Skipping duplicate of %r" % (duplicates, ))
            return duplicates[0]

        title = make_title(photo.metadata, self.front_titlefmt,
                           self.rear_titlefmt, self.variable_titlefmt)

        description = textlib.glue_template_and_params((self.pagefmt,
                                                        photo.metadata))
        print title

        bot = upload.UploadRobot(url = photo.URL,
                                 description = description,
                                 useFilename = title,
                                 keepFilename = True,
                                 verifyDescription = False,
                                 targetSite = self.site)
        bot._contents = photo.downloadPhoto().getvalue()
        bot._retrieved = True
        bot.run()
        return title
Example #8
0
    def treat_page(self):
        """Load the given page, do some changes, and save it."""
        refR = re.compile(r'(?P<all><ref.*?</ref>)')
        # clenaupR = re.compile(r'(?i){{dopracować.*?}}')
        text = self.current_page.text
        links = {
            'links': 0,
            'cat': 0,
            'template': 0,
            'infobox': 0,
            'refs': 0,
            'dopracować': False
        }
        # cleanupTmpl = False
        summary = []

        if self.current_page.isRedirectPage():
            pywikibot.output(u'Page %s is REDIRECT!' %
                             self.current_page.title())
            return
        elif self.current_page.isDisambig():
            pywikibot.output(u'Page %s is DISAMBIG!' %
                             self.current_page.title())
            return
        else:
            if self.opt.test:
                pywikibot.output(u'Title:%s' % self.current_page.title())
                pywikibot.output(u'Depth:%s' % self.current_page.depth)
            for l in self.current_page.linkedPages(namespaces=0):
                if self.opt.test:
                    pywikibot.output(u'Links to:[[%s]]' % l.title())
                links['links'] += 1
                # pywikibot.output(u'Links:%s' % len(list(self.current_page.linkedPages(namespaces=0))))
            for t, p in textlib.extract_templates_and_params(
                    text, remove_disabled_parts=True):
                if self.opt.test:
                    pywikibot.output('Template:[[%s]]' % t)
                links['template'] += 1
                if 'infobox' in t:
                    links['infobox'] += 1
                if 'dopracować' in t.lower():
                    links['dopracować'] = True
                if t.lower(
                ) in tmplcat:  #  check for category adding templates
                    links['cat'] += 1
                    if self.opt.test:
                        pywikibot.output('Current cat#%i' % links['cat'])
                    # cleanupTmpl = (t, p)
                # if 'rok w' in t or 'Rok w' in t:
                #     links['cat'] += 1

            for c in textlib.getCategoryLinks(text):
                if self.opt.test:
                    pywikibot.output('Category:%s' % c)
                links['cat'] += 1
                if self.opt.test:
                    pywikibot.output('Current cat#%i' % links['cat'])
            for r in refR.finditer(text):
                if self.opt.test:
                    pywikibot.output('Ref:%s' % r.group('all'))
                links['refs'] += 1
            if self.opt.test:
                pywikibot.output('Links=%s' % links)
                # pywikibot.output('Cleanup=%s' % re.sub('\n','',textlib.glue_template_and_params(cleanupTmpl)))

        if links['dopracować']:
            if self.opt.test:
                pywikibot.output('Cleanup Tmpl FOUND')
        else:
            # add {{Dopracować}}
            t = 'Dopracować'  # template title
            p = {}  # template params
            today = datetime.now()
            datestr = today.strftime('%Y-%m')
            if self.opt.test:
                pywikibot.output('Date:%s' % datestr)
            if not (links['links'] and links['cat']):
                if not links['links']:
                    p['linki'] = datestr
                    summary.append('linki')
                if not links['cat']:
                    p['kategoria'] = datestr
                    summary.append('kategorie')
                # if not links['refs']:
                #    p['przypisy'] = datestr
                #    summary.append('przypisy')
            cleanupTmpl = (t, p)

            if not p:
                if self.opt.test:
                    pywikibot.output('Nothing to add')
                return

            if self.opt.test:
                pywikibot.output('Cleanup Tmpl TO ADD')
                pywikibot.output('summary:%s' % summary)
                pywikibot.output('params:%s' % p)
            text = re.sub(
                '\n', '',
                textlib.glue_template_and_params(cleanupTmpl)) + '\n' + text

            # if summary option is None, it takes the default i18n summary from
            # i18n subdirectory with summary_key as summary key.
            self.put_current(
                text,
                summary=
                'Sprawdzanie nowych stron, w artykule należy dopracować: %s' %
                ','.join(summary))
Example #9
0
 def to_template(self, template=u'Ingestion layout'):
     """Return the Record as a MediaWiki template."""
     return textlib.glue_template_and_params((template,
                                              self.__dict__))