Difference between revisions of "Talk:List of XEPs"

From JaWiki (Jabber/XMPP wiki)
Jump to: navigation, search
m (Проверка списка: эти скобки только энтропию Вселенной увеличивают)
m (Reverted edits by 46.161.9.50 (talk) to last revision by Binary)
 
(34 intermediate revisions by 19 users not shown)
Line 1: Line 1:
== Генерация списка ==
+
== Скрипт для генерации и проверки списка ==
  
Копипаст оригинального списка прогнать через этот скрипт:
+
Требуется [[Python]] 3
  
  #! /usr/bin/env perl
+
  <nowiki>#! /usr/bin/env python3
+
# -*- 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";
+
}
+
  
== Проверка списка ==
 
  
Требуется [[Python]] 3
+
# input
 +
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('[=] Различия не найдены.')
 +
 
  
#! /usr/bin/env python3
+
if __name__ == '__main__':
# -*- coding: utf-8 -*-
+
    #initXepList()
+
    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('_', ' ')
+
            xepstatus = search.group(2)
+
            continue
+
        search = re.search('xep-([0-9]{4}).*\|\| (.*)<hr', line)
+
        if search:
+
            xeps[search.group(1)] = {
+
                'name': search.group(2),
+
                '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()
+

Latest revision as of 13:20, 13 June 2017

Скрипт для генерации и проверки списка[edit]

Требуется Python 3

#! /usr/bin/env python3
# -*- coding: utf-8 -*-


# input
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__':
    #initXepList()
    main()