Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import login
- import time
- from lists import pairs
- API_URL = 'https://ru.wikinews.org/w/api.php'
- USER_AGENT = {"User-Agent": "IluvatarBot; iluvatar@tools.wmflabs.org; python3.9; requests"}
- def delete_page(title, summary, token, cookies):
- params = {'action': "delete", 'title': title, 'token': token, 'format': "json", 'reason': summary, 'utf8': 1}
- r = requests.post(API_URL, data=params, cookies=cookies, headers=USER_AGENT)
- print(r.json())
- def move_page(from_title, to_title, summary, token, cookies, supress=0, move_subpages=1, move_talk=1):
- params = {"action": "move", "noredirect": supress, "movesubpages": move_subpages, "token": token,
- "format": "json", "utf8": 1, "from": from_title, "to": to_title, "reason": summary, "movetalk": move_talk}
- r = requests.post(API_URL, data=params, cookies=cookies, headers=USER_AGENT)
- print(r.json())
- def edit_page(title, text, summary, token, cookies):
- params = {"action": "edit", "title": title, 'recreate': 0, 'nocreate': 0,
- "token": token, 'bot': 1, 'summary': summary, "format": "json", 'utf8': 1, "text": text}
- r = requests.post(url=API_URL, data=params, cookies=cookies, headers=USER_AGENT)
- print(r.json())
- def check_backlinks(title, namespaces):
- params = {"action": "query", "format": "json", "list": "backlinks",
- "bltitle": title, 'blnamespace': namespaces, 'utf8': 1, 'bllimit': 500}
- r = requests.post(url=API_URL, data=params)
- resp = r.json()["query"]["backlinks"]
- return len(resp), [i for i in resp if i['ns'] == 0 if 'redirect' in i]
- def utf8len(s):
- return len(s.encode('utf-8'))
- counter = 0
- for page in pairs.storage3:
- if "&" not in page[0] or ";" not in page[0] or repr(page[1])[1] == '\\':
- continue
- print('\n'*19)
- if input(f"""\033[36m{'Не влезет что-то!' if utf8len('Статистика страниц/Комментарии:' + repr(page[1])) > 255 else ''}\033[0m
- \033[31m{repr(page[0])}\033[0m
- \033[32m{repr(page[1])}\033[0m
- Будет удалено:
- \t\t\033[31m{page[1]}\033[0m
- \t\t\033[31mВикиновости:Статистика страниц/{page[1]}\033[0m
- Будет переименовано:
- \t\t\033[31m{page[0]}\033[0m
- \t\t\033[31mКомментарии:{repr(page[0])}\033[0m
- \t\t\033[31mВикиновости:Статистика страниц/{repr(page[0])}\033[0m
- \t\t\033[31mВикиновости:Статисватика страниц/Комментарии:{repr(page[0])}\033[0m
- Будет отредактировано:
- \t\t\033[31mВикиновости:Статистика страниц/{repr(page[0])}\033[0m
- \t\t\033[31mВикиновости:Статистика страниц/Комментарии:{repr(page[0])}\033[0m
- Начинаем? Enter:\n""").lower() == "":
- summ = "Ошибка в названии ([[Викиновости:Форум/Общий#Битые заголовки|more info]]) ([[m:GS|global sysop]] action)"
- summ2 = 'Для возможности переименования ([[Викиновости:Форум/Общий#Битые заголовки|more info]]) ([[m:GS|global sysop]] action)'
- token, cookies = login.login(is_bot=False, server="ru.wikinews")
- delete_page(page[1], summ2, token, cookies)
- time.sleep(2)
- delete_page(f'Викиновости:Статистика страниц/{page[1]}', summ2, token, cookies)
- time.sleep(2)
- token, cookies = login.login(is_bot=True, server="ru.wikinews")
- move_page(page[0], page[1], summ, token, cookies, supress=1)
- time.sleep(2)
- move_page(f'Комментарии:{page[0]}', f'Комментарии:{page[1]}', summ, token, cookies, supress=1)
- time.sleep(2)
- move_page(f'Викиновости:Статистика страниц/{page[0]}', f'Викиновости:Статистика страниц/{page[1]}', summ,
- token, cookies, supress=1)
- time.sleep(2)
- edit_page(f'Викиновости:Статистика страниц/{page[1]}', '{{Статистика страницы|' + page[1] + '}}',
- 'Переименовано', token, cookies)
- time.sleep(2)
- move_page(f'Викиновости:Статистика страниц/Комментарии:{page[0]}',
- f'Викиновости:Статистика страниц/Комментарии:{page[1]}', summ, token, cookies, supress=1)
- time.sleep(2)
- edit_page(f'Викиновости:Статистика страниц/Комментарии:{page[1]}', '{{Статистика страницы|Комментарии:' + page[1] + '}}',
- 'Переименовано', token, cookies)
- check = True
- backlinks, redirects = check_backlinks(page[0], '0|4|14|102')
- if backlinks > 0:
- if len(redirects) == 1:
- print('Исправляем редирект')
- edit_page(f'{redirects[0]["title"]}', f'#REDIRECT [[{page[1]}]]', 'Переименовано', token, cookies)
- backlinks, redirects = check_backlinks(page[0], '0|4|14|102')
- if backlinks > 0:
- check = False
- else: check = False
- backlinks, redirects = check_backlinks(f'Викиновости:Статистика страниц/{page[0]}', '0|4|14|102')
- if backlinks > 0: check = False
- backlinks, redirects = check_backlinks(f'Комментарии:{page[0]}', '0|4|14|102')
- if backlinks > 0: check = False
- backlinks, redirects = check_backlinks(f'Викиновости:Статистика страниц/Комментарии:{page[0]}', '0|4|14|102')
- if backlinks > 0: check = False
- if check is False:
- input(f"""Проверить обратные ссылки после переименований:
- \t\t\033[33m{page[0]}\033[0m
- \t\t\033[33mКомментарии:{page[0]}\033[0m
- \t\t\033[33mВикиновости:Статистика страниц/{page[0]}\033[0m
- \t\t\033[33mВикиновости:Статистика страниц/Комментарии:{page[0]}\033[0m
- Выполните проверку редиректов и нажмите Enter.""")
- counter += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement