Editing Talk:List of XEPs

From JaWiki (Jabber/XMPP wiki)
Jump to: navigation, search

Warning: The database has been locked for maintenance, so you will not be able to save your edits right now. You may wish to copy and paste your text into a text file and save it for later.

The administrator who locked it offered this explanation: MediaWiki upgrading

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
== Скрипт для генерации и проверки списка ==
+
== Генерация списка ==
  
Требуется [[Python]] 3
+
Копипаст оригинального списка прогнать через этот скрипт:
  
  <nowiki>#! /usr/bin/env python3
+
  #! /usr/bin/env perl
# -*- coding: utf-8 -*-
+
 +
while ( <> )
 +
{
 +
split '\t';
 +
 +
chop @_;
 +
$xep = $_[0];
 +
$name = $_[1];
 +
$type = $_[2];
 +
$status = $_[3];
 +
$date = $_[4]; # ignored
 +
 +
# XEP -> template
 +
$xep =~ /XEP-([0-9]{4})/;
 +
$xep = "<nowiki>{{xep|$1}}</nowiki>";
 +
 +
# add place for the russian translation
 +
$name = $name."&lt;hr/&gt;";
 +
 +
# type and status translation, according to [[Terms]]
 +
%TypeTranslation =
 +
(
 +
"Historical", "Историческое",
 +
"Humorous", "Шуточное",
 +
"Informational", "Информационное",
 +
"JIG Formation", "Формирование JIG",
 +
"Procedural", "Процедурное",
 +
"Standards Track", "Основное"
 +
);
 +
%StatusTranslation =
 +
(
 +
"Active", "Действующее",
 +
"Deferred", "Отложенное",
 +
"Deprecated", "Отменённое",
 +
"Draft", "Черновик",
 +
"Experimental", "Экспериментальное",
 +
"Final", "Окончательное",
 +
"Obsolete", "Устаревшее",
 +
"Proposed", "Предложенное",
 +
"Rejected", "Отклонённое",
 +
"Retracted", "Отозванное"
 +
);
 +
 +
$typeTranslated = $TypeTranslation{$type};
 +
$statusTranslated = $StatusTranslation{$status};
 +
 +
# type, status links and classes
 +
$typeClass = 'type_'.$type;
 +
$statusClass = 'status_'.$status;
 +
$type = "<nowiki>[[XEP#Типы|$typeTranslated]]</nowiki>";
 +
$status = "<nowiki>[[XEP#Статусы|$statusTranslated]]</nowiki>";
 +
$typeClass =~ s/ /_/g;
 +
$statusClass =~ s/ /_/g;
 +
 +
# outting table row
 +
print "|- class='$typeClass $statusClass'\n| $xep || $name || $type || $status\n";
 +
}
  
 +
== Проверка списка ==
  
# input
+
Требуется [[Python]] 3
XEPS_ORIG_URL = 'http://xmpp.org/extensions/xeps.xml'
+
XEPS_WIKI_URL_T = 'http://jawiki.ru/index.php?title={}&action=raw'
+
XEPS_WIKI_URL_PAGES = (
+
    'Список_расширений/0001—0049',
+
    'Список_расширений/0050—0099',
+
    'Список_расширений/0100—0149',
+
    'Список_расширений/0150—0199',
+
    'Список_расширений/0200—0249',
+
    'Список_расширений/0250—0299'
+
)
+
 
+
 
+
import itertools
+
import re
+
import sys
+
import urllib.request
+
import xml.etree.ElementTree as xml
+
 
+
 
+
def fetchUrl(url):
+
    return urllib.request.urlopen(url).read().decode('UTF-8')
+
 
+
 
+
def initXepList():
+
    print('... Получение оригинального списка расширений... ', end='', file=sys.stderr)
+
    sys.stderr.flush()
+
    xeps_orig_xml = xml.XML(fetchUrl(XEPS_ORIG_URL))
+
    print('Готово.', file=sys.stderr)
+
   
+
    xeps_orig = {}
+
    for xep in xeps_orig_xml:
+
        number = xep.find('number').text
+
        xeps_orig[number] = {
+
            'name': xep.find('name').text,
+
            'abstract': xep.find('abstract').text,
+
            'type': xep.find('type').text.replace(' ', '_'),
+
            'status': xep.find('status').text
+
        }
+
   
+
    for number in sorted(xeps_orig):
+
        print(
+
            '{{{{XepListItem|{number}|{name}|{abstract}|||{type}|{status}}}}}'
+
                .format(number=number, **xeps_orig[number])
+
        )
+
 
+
 
+
def main():
+
    print('... Получение списка расширений из ЯВики... ', end='')
+
    xeps_wiki = itertools.chain(*(
+
        fetchUrl(XEPS_WIKI_URL_T.format(urllib.parse.quote(page))).splitlines()
+
        for page in XEPS_WIKI_URL_PAGES
+
    ))
+
    print('Готово.')
+
   
+
    xeps = {}
+
    for line in xeps_wiki:
+
        line = line[2:-2] # убираем двойные фигурные скобки по краям, если есть
+
        line = re.sub(r'\{\{.*?\}\}', '', line) # вырезаем вызовы викишаблонов, в них могут быть палки
+
        line = re.sub(r'\[\[.*?\]\]', '', line) # вырезаем викиссылки, в них могут быть палки
+
        parts = line.split('|')
+
        if parts[0] == 'XepListItem':
+
            xeps[parts[1]] = {
+
                'name': parts[2],
+
                'type': parts[6].replace('_', ' '),
+
                'status': parts[7]
+
            }
+
   
+
    print('... Прочитано %d расширений.' % len(xeps))
+
   
+
    print('... Получение оригинального списка расширений... ', end='')
+
    xeps_orig_xml = xml.XML(fetchUrl(XEPS_ORIG_URL))
+
    print('Готово.')
+
   
+
    xeps_orig = {}
+
    for xep in xeps_orig_xml:
+
        number = xep.find('number').text
+
        xeps_orig[number] = {
+
            'name': xep.find('name').text,
+
            'type': xep.find('type').text,
+
            'status': xep.find('status').text
+
        }
+
   
+
    differ = False
+
    for number in sorted(xeps_orig):
+
        if number not in xeps:
+
            differ = True
+
            print('[*] Новое расширение: XEP-' + number)
+
            print('\tНазвание: ' + xeps_orig[number]['name'])
+
            print('\tТип: ' + xeps_orig[number]['type'])
+
            print('\tСтатус: ' + xeps_orig[number]['status'])
+
        elif xeps[number] != xeps_orig[number]:
+
            differ = True
+
            print('[*] Различается XEP-' + number)
+
            if xeps[number]['name'] != xeps_orig[number]['name']:
+
                print('\tНазвание изменено с "{0}" на "{1}"'.format(xeps[number]['name'], xeps_orig[number]['name']))
+
            if xeps[number]['type'] != xeps_orig[number]['type']:
+
                print('\tТип изменён с "{0}" на "{1}"'.format(xeps[number]['type'], xeps_orig[number]['type']))
+
            if xeps[number]['status'] != xeps_orig[number]['status']:
+
                print('\tСтатус изменён с "{0}" на "{1}"'.format(xeps[number]['status'], xeps_orig[number]['status']))
+
   
+
    if not differ:
+
        print('[=] Различия не найдены.')
+
 
+
  
if __name__ == '__main__':
+
#! /usr/bin/env python3
    #initXepList()
+
# -*- coding: utf-8 -*-
    main()</nowiki>
+
 +
 +
# input
 +
XEPS_ORIG_URL = 'http://xmpp.org/includes/xeps-all.txt'
 +
XEPS_WIKI_URL = 'http://wiki.jrudevels.org/List_of_XEPs?action=raw&templates=expand'
 +
 +
 +
import re
 +
import urllib.request
 +
 +
 +
def fetchUrl(url):
 +
    return str(urllib.request.urlopen(url).read(), 'UTF-8')
 +
 +
 +
def main():
 +
    print('... Получение списка расширений из ЯВики... ', end=<nowiki>''</nowiki>)
 +
    xeps_wiki = fetchUrl(XEPS_WIKI_URL).splitlines()
 +
    print('Готово.')
 +
   
 +
    xeps = {}
 +
    xeptype = None
 +
    xepstatus = None
 +
    for line in xeps_wiki:
 +
        search = re.search("class='type_(.*?) status_(.*?)'", line)
 +
        if search:
 +
            xeptype = search.group(1).replace('_', ' ').strip()
 +
            xepstatus = search.group(2).strip()
 +
            continue
 +
        search = re.search('xep-([0-9]{4}).*\|\|(.*)<hr', line)
 +
        if search:
 +
            xeps[search.group(1)] = {
 +
                'name': search.group(2).strip(),
 +
                'type': xeptype,
 +
                'status': xepstatus
 +
            }
 +
   
 +
    print('... Прочитано %d расширений.' % len(xeps))
 +
   
 +
    print('... Получение оригинального списка расширений... ', end=<nowiki>''</nowiki>)
 +
    xeps_orig = fetchUrl(XEPS_ORIG_URL).split('</tr>\n<tr')
 +
    print('Готово.')
 +
   
 +
    differ = False
 +
    for xepblock in xeps_orig:
 +
        xepdetails = re.findall('<td[^>]*>(.*)</td>', xepblock)
 +
        xepcode = xepdetails[0][55:59]
 +
        xep_o = {
 +
            'name': xepdetails[1],
 +
            'type': xepdetails[2],
 +
            'status': xepdetails[3]
 +
        }
 +
        if xepcode not in xeps:
 +
            differ = True
 +
            print('[*] Новое расширение: XEP-' + xepcode)
 +
            print('\tНазвание: ' + xep_o['name'])
 +
            print('\tТип: ' + xep_o['type'])
 +
            print('\tСтатус: ' + xep_o['status'])
 +
        elif xep_o != xeps[xepcode]:
 +
            differ = True
 +
            print('[*] Различается XEP-' + xepcode)
 +
            if xep_o['name'] != xeps[xepcode]['name']:
 +
                print('\tНазвание изменено с "{0}" на "{1}"'.format(xeps[xepcode]['name'], xep_o['name']))
 +
            if xep_o['type'] != xeps[xepcode]['type']:
 +
                print('\tТип изменён с "{0}" на "{1}"'.format(xeps[xepcode]['type'], xep_o['type']))
 +
            if xep_o['status'] != xeps[xepcode]['status']:
 +
                print('\tСтатус изменён с "{0}" на "{1}"'.format(xeps[xepcode]['status'], xep_o['status']))
 +
   
 +
    if not differ:
 +
        print('[=] Различия не найдены.')
 +
 +
 +
if __name__ == '__main__':
 +
    main()

Please note that all contributions to JaWiki (Jabber/XMPP wiki) may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see JaWiki (Jabber/XMPP wiki):Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)