Example #1
0
 def save_step(self):
     if os.path.exists('stop'):
         print u'Stopping command because "stop" file exists.'
         self.stop()
     if not self.last_action_filename:
         raise NotImplementedError()
     # print '@', self.current_datetime, '-', "type: ", \
     #     self.last_action_filename
     if os.path.exists(self.state_filename):
         # print '# File exists'
         content = load_file(self.state_filename)
         last_action = datetime.strptime(content, self.date_format)
         # print last_action
         # print datetime.now()
         delta = datetime.now() - last_action
         # print delta
         if delta < timedelta(seconds=5):
             # print '<<<'
             # print
             return
     # save_file(self.last_action_filename, self.current_datetime)
     try:
         # print 'SAVED!!!', '@' * 100
         save_file(self.state_filename, self.current_datetime)
         append_file(u'files/logs/%s-s' % self.last_action_filename,
                     u'%s - %s' % (self.current_datetime, self.i))
     except IOError:
         # pass
         # print
         print u'### IOError', '#' * 200
Example #2
0
    def make_change(self, title, old_content, new_content):
        if new_content != old_content:
            if not self.report_name:
                raise Exception('Need `report_name` file')
            desc = self.change_description()
            new_content = self.additional_change_content(new_content)
            save_wiki_page(title, new_content, desc, wait=5)

            # 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')
Example #3
0
    def langs_action(self, page, sections):
        change_required = False
        for section in sections[1:]:
            old_section = section['content']
            new_section = self.lang_action(page, section['lang'], old_section)
            if old_section != new_section:
                change_required = True
                break
        if change_required:
            try:
                old_content = new_content = self.get_content(page.title)
                if old_content != page.content:

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

                    # send_wiki_mail(u"Скорее всего utf8mb4: " + page.title,
                    #                page.title)
                    print '#' * 100, 'DIFFERENT CONTENT', '!' * 10
                for section in sections[1:]:
                    old_section = section['content']
                    new_section = self.lang_action(page, section['lang'],
                                                   old_section)
                    # if old_section != new_section:
                    #     print 'ok1'
                    #     if old_section in new_content:
                    #         print 'ok2'
                    #     if old_section in old_content:
                    #         print 'ok3'
                    new_content = new_content.replace(old_section, new_section)
                self.change_counter += 1
                # print self.debug, page.title
                if self.debug:
                    self.print_debug_info(page, old_content, new_content)
                    return
                self.make_change(page.title, old_content, new_content)
            except NoPage:
                print '#' * 100, 'NoPage'
            except LockedPage:
                print '#' * 100, 'LockedPage'
Example #4
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 #5
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 #6
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')