Beispiel #1
0
def remove_template(title, day, month, year):
    content, template = prepare_template(title, day, month, year)
    if not content:
        return
    link = get_title_link(title)
    if template not in content:
        send(f'❌ <b>Ошибка:</b> Нет шаблона в {link}')
        return
    content = content.replace(f'{template}\n', '')
    content = content.replace(f'{template}', '')
    if not debug:
        save_page(title, content, 'Удаление шаблона {{слово дня}}')
Beispiel #2
0
def save_pages():
    endings = json.loads(read('endings_ru_new.json'))
    for ending, entries in endings.items():
        entries.sort(key=lambda x: x[0][::-1])
        values = [entry[1] for entry in entries]
        for i, chunk in enumerate(chunks(values, 3700)):
            # content = f"= Глаголы на '''-{ending}''' =\n" \
            #           f'<div class="reverseindex">\n' + \
            #           f''.join(chunk) + \
            #           f'</div>'
            content = f"= Глаголы на '''-{ending}''' =\n" + f''.join(chunk)
            save_page(f'User:Vitalik/reports/verbs/-{ending}/{i+1}', content,
                      'Обратный список глаголов по окончаниям')
            print(ending, len(chunk))
Beispiel #3
0
 def upload_changes(self, desc, minor=True, debug=False):
     server_content = load_page(self.title)
     if server_content != self._old_content:
         raise Exception('Content on the server was suddenly changed.')
     new_content = self.new_content
     if new_content != self._old_content:
         if debug:
             print('=' * 10)
             print(self.title)
             print('-' * 10)
             print(new_content)
             print('-' * 10)
             return
         save_page(self.title, new_content, desc, minor, check_changes=False)
Beispiel #4
0
def add_template(title, day, month, year):
    content, template = prepare_template(title, day, month, year)
    if not content:
        return
    link = get_title_link(title)
    if template in content:
        send(f'❌ <b>Ошибка:</b> Шаблон уже есть в {link}')
        return
    if '{{слово дня|' in content:
        send(f'❌ <b>Ошибка:</b> Другой шаблон в {link}')
        return
    content = f'{template}\n\n{content}'
    if not debug:
        save_page(title, content, 'Добавление шаблона {{слово дня}}')
Beispiel #5
0
def upload(dev, ru_noun_version, inflection_version, desc):
    if not compare_dir('lua'):
        print('Ошибка: папки `lua` не синхронизированы.')
        return

    desc = process_desc(dev, desc)

    path = get_path('lua')
    print(f'Загружаю lua-модули в ВС:')

    for file in files:
        title = get_module_title(file, dev)
        print(f'- {title} - ', end='')

        file = file.replace('[.out]', '.out')
        if save_page(title, read_file(dev, f'{path}/{file}.lua'),
                     f'v{ru_noun_version}: {desc}'):
            print('OK')

    dev_prefix = 'User:Vitalik/' if dev else ''
    title = f'Module:{dev_prefix}inflection/tools'
    path = get_path('lua', noun=False)
    save_page(title, read_file(dev, f'{path}/tools.lua'),
              f'v{inflection_version}: {desc}')
Beispiel #6
0
def upload_docs(version, desc, dev):
    desc = process_desc(dev, version, desc)
    print(f'Загружаю документацию в ВС:')

    files = declension_files + testcases_files
    for file in files:
        title = get_docs_title(file, dev)
        print(f'- {title} - ', end='')

        path = get_path(dev, 'docs', file, out=False)
        if not exists(path):
            print('Not exist')
            continue
        if save_page(title, read_file(dev, path), f'v{version}: {desc}'):
            print('OK')
Beispiel #7
0
def upload_lua(version, desc, dev, testcases=False):
    if not compare_dir(dev, 'lua'):
        print('Ошибка: папки `lua` не синхронизированы.')
        return

    desc = process_desc(dev, version, desc)

    print(f'Загружаю lua-модули в ВС:')

    files = testcases_files if testcases else declension_files
    for file in files:
        title = get_module_title(file, dev)
        print(f'- {title} - ', end='')

        path = get_path(dev, 'lua', file, out=True)
        if save_page(title, read_file(dev, path), f'v{version}: {desc}'):
            print('OK')
Beispiel #8
0
    def start(self):
        name = re.search(u':Cinemantique/(.+)', self.data_page).group(1)

        if f'* [[{self.data_page}|{name}]] = on' \
                not in load_page(u'User:Cinemantique/bot'):
            print(f'Bot `{self.data_page}` is offline.')
            return

        entries = load_page(self.data_page).strip()
        if not entries:
            print(f'Page `{self.data_page}` is empty.')
            return

        self.report.status('Бот запущен')

        processed = []
        for i, entry in enumerate(entries.split('\n\n')):
            title, *values = entry.split('\n ')
            if not values:
                continue
            if not self.check_entries(title, values):
                continue
            if title in processed:
                self.report.error(title, 'дублируется в списке')
                continue
            processed.append(title)
            try:
                if self.debug:
                    page = StoragePage(title, silent=True)
                else:
                    page = OnlinePage(title, silent=True)
            except PageNotFound:
                self.report.error(title, 'в ВС нет статьи')
                continue
            if page.is_redirect:
                self.report.error(title, 'статья-редирект')
                continue
            if not page.ru:
                self.report.error(title, 'нет русского раздела в статье')
                continue
            if len(page.ru.homonyms.all()) > 1:
                self.report.error(title, 'омонимы в статье')
                continue

            if not self.process_page(page, title, values):
                continue

            try:
                if not self.debug:
                    page.upload_changes(self.desc)
            except Exception:
                self.report.error(title, 'что-то пошло не так')
                self.report.save('unexpected error')
                raise

            self.report.success(title)

        self.report.status('Бот завершён')

        if not self.debug:
            desc = f'Готово: [[{self.data_page}/report|отчёт]]'
            save_page(self.data_page, '', desc)
Beispiel #9
0
 def append(self, report_title, lines, desc):
     title = f"{self.base.data_page}/{report_title}"
     old_content = load_page(title, skip_absent=True)
     if not self.base.debug:
         save_page(title, f'{old_content}\n{lines}', desc)
Beispiel #10
0
def sync_save_page(title, content, desc, debug=False):
    sync_save(title, content)
    if debug:
        print(f'{"=" * 100}\n{title}\n{content.strip()}\n')
    else:
        save_page(title, content, desc)
Beispiel #11
0
def save_new_page(title, content, desc='Заливка деепричастий'):
    try:
        load_page(title)
        return
    except NoPage:
        save_page(title, content, desc)