def section_action(self, page, lang, section_content):
     super(ReplaceOldEmptyMorphoRu, self).section_action(page, lang, section_content)
     title = page.title
     if lang != 'ru':
         return
     m = re.search(u'(=== *Морфологические и синтаксические свойства *=== *(.*?)\n)=',
                   section_content, re.UNICODE | re.DOTALL)
     if not m:
         return
     old_body = m.group(2)
     p = re.compile(
         u"""(\{\{
             (?P<title>морфо\s*)  # заголовок
             \|(?P<params>[^{}]+?(\{\{[^{}]+?\}\})?[^{}]+?)  # параметры
             \}\})""",
         flags=re.UNICODE + re.DOTALL + re.VERBOSE)
     parts = p.findall(old_body)
     new_body = old_body
     for part in parts:
         old_params = part[2]
         params = old_params
         params = re.sub(u'(префд|прист|суфф-?|корень|инф|соед|оконч-?|интер|суффд|частица|постфикс)\d*=', '', params)
         params = re.sub(u'\|', '', params).strip()
         if not params:
             # append_dict_list(self.old_empty_morpho, title, part[0])
             new_body = new_body.replace(part[0], u'{{морфо-ru|}}')
         # params = part[2].strip().split('|')
         # for value in params:
         #     value = value.strip()
         #     if '=' in value:
         #         name, value = value.split('=', 1)
         #     if '-' in value:
         #         append_dict_list(self.morpho_wrong_hyphens, title, part[0])
         #         break
     if old_body != new_body:
         # print '=' * 100
         # print old_body
         # print '-' * 100
         # print new_body
         # print '=' * 100
         old_section_content = section_content
         new_section_content = section_content.replace(old_body, new_body)
         try:
             old_content = get_wiki_page_content(title)
         except NoPage:
             send_wiki_mail(subject="pywikibot.exceptions.NoPage: " + title,
                            message=title)
             return
         except IsRedirectPage:
             send_wiki_mail(
                 subject="pywikibot.exceptions.IsRedirectPage: " + title,
                 message=title)
             return
         new_content = old_content.replace(old_section_content, new_section_content)
         if new_content != old_content:
             desc = u"Замена пустого {{морфо}} на пустой {{морфо-ru}}"
             save_wiki_page(title, new_content, desc)
Example #2
0
 def handle(self, *args, **options):
     if not self.name:
         raise NotImplementedError()
     append_file('files/timing', u'%s @ %s' % (self.current_datetime, self.name))
     print '@', self.current_datetime, '-', "Starting wikt command:", \
         self.name
     is_started = os.path.exists(self.state_filename)
     if is_started:
         print '# Command already started'
         if not self.skip_mail:
             send_wiki_mail(
                 subject="Wikt command already started: " + self.name,
                 message=open(self.state_filename).read()
             )
         return
     save_file(self.state_filename,
               "Started at " + self.current_datetime)
     self.wikt_handle(*args, **options)
     os.remove(self.state_filename)
     append_file('files/timing', u'%s . %s' % (self.current_datetime, self.name))
Example #3
0
 def check_for_start(self):
     if not self.last_action_filename:
         raise NotImplementedError()
     last_action = datetime.now()  # default value for email
     delta = 'None'
     if os.path.exists(self.state_filename):
         content = load_file(self.state_filename)
         last_action = datetime.strptime(content, self.date_format)
         delta = datetime.now() - last_action
         if delta < timedelta(minutes=3) and not self.skip_mail:
             print "Don't start yet: " + self.last_action_filename
             send_wiki_mail(
                 subject="Don't start yet: " + self.last_action_filename,
                 message="%s // %s" % (last_action, delta)
             )
             raise Exception("Don't start yet!!")
     print "Successfully started: " + self.last_action_filename
     send_wiki_mail(
         subject="Successfully started: " + self.last_action_filename,
         message="%s // %s" % (last_action, delta)
     )
     append_file('files/timing',
                 u'%s > %s' % (self.current_datetime_Kyiv,
                               self.last_action_filename))
Example #4
0
    def section_action(self, page, lang, section_content):
        super(ReplaceOldMorphoRu, self).section_action(page, lang, section_content)
        title = page.title
        if lang != 'ru':
            return
        m = re.search(u'(=== *Морфологические и синтаксические свойства *=== *(.*?)\n)=',
                      section_content, re.UNICODE | re.DOTALL)
        if not m:
            return
        old_body = m.group(2)
        p = re.compile(
            u"""(\{\{
                (?P<title>морфо\s*)  # заголовок
                \|(?P<params>[^{}]+?(\{\{[^{}]+?\}\})?[^{}]+?)  # параметры
                \}\})""",
            flags=re.UNICODE + re.DOTALL + re.VERBOSE)
        parts = p.findall(old_body)
        new_body = old_body
        # print title.encode('utf-8')
        for part in parts:
            old_params = part[2]
            is_title = old_params
            is_title = re.sub(u'(префд|прист|суфф-?|корень|инф|соед|оконч-?|интер|суффд|частица|постфикс|источник)\d*=', '', is_title)
            is_title = re.sub(u'\|', '', is_title).strip()
            if is_title == title or is_title == title + u'т' or is_title == title + u'к':
                # print
                # print title
                # print part[0]
                # {{морфо||адрес|ова|суфф2=нн|ый}}
                try:
                    sres = get_sorted_list(get_old_list(old_params))
                except ValueError as e:
                    print title.encode('utf-8')
                    # sent = False
                    # try:
                    #     send_mail(subject="morpho exception in: " + title,
                    #                       message=title + "\n\n" + repr(e),
                    #                       from_email=settings.DEFAULT_FROM_EMAIL,
                    #                       recipient_list=['*****@*****.**'])
                    #     sent = True
                    # except:
                    #     pass
                    # if sent:
                    #     return
                    # else:
                    #     raise
                    raise

                # for key, value in sres:
                #     print "- %s = '%s'" % (key, value)
                res = get_new_list(sres)
                ress = '|'.join(res)
                # print ress
                new_body = new_body.replace(part[0], u'{{морфо-ru|%s}}' % ress)
                # params = part[2].strip().split('|')
                # for value in params:
                #     value = value.strip()
                #     if '=' in value:
                #         name, value = value.split('=', 1)
                #     if '-' in value:
                #         append_dict_list(self.morpho_wrong_hyphens, title, part[0])
                #         break
            elif not is_title:
                new_body = new_body.replace(part[0], u'{{морфо-ru|}}')
        if old_body != new_body:
            # print '=' * 100
            # print old_body
            # print '-' * 100
            # print new_body
            # print '=' * 100
            old_section_content = section_content
            new_section_content = section_content.replace(old_body, new_body)
            try:
                old_content = get_wiki_page_content(title)
            except NoPage:
                send_wiki_mail(subject="pywikibot.exceptions.NoPage: " + title,
                               message=title)
                return
            except IsRedirectPage:
                send_wiki_mail(
                    subject="pywikibot.exceptions.IsRedirectPage: " + title,
                    message=title
                )
                return
            new_content = old_content.replace(old_section_content, new_section_content)
            if new_content != old_content:
                desc = u"Замена {{морфо}} на {{морфо-ru}}"
                # self.n_step += 1
                # if self.n_step >= 100:
                #     self.stop()
                new_content = default_wikifier(new_content)
                save_wiki_page(title, new_content, desc)

                # todo: create special function for this:
                d = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                append_file(os.path.join(settings.FILES_PATH, 'reports',
                                         self.report_name),
                            "%s: %s" % (d, title),
                            encode='utf-8')