For faster navigation, this Iframe is preloading the Wikiwand page for User:Sz-iwbot/rater/rater.py.

User:Sz-iwbot/rater/rater.py

#!/usr/bin/python
# -*- coding: utf-8 -*-
import pywikibot
import json
import collections

site = pywikibot.Site()
#--------------------------------
jsonpage = pywikibot.Page(site, u"User:Sz-iwbot/rater/aliases.json")
jsontext = jsonpage.text
aliasesdict = json.loads(jsontext)
print('Loading data....')

#检查现有数据,删除不存在的重定向,修复错误的重定向
print('Check current data....')
for item in list(aliasesdict.keys()):
    tempalte = "Template:"+item
    tpage = pywikibot.Page(site, tempalte)
    if tpage.exists():
        if tpage.isRedirectPage():
            #print(item+ ' is RedirectPage')
            tname = tpage.getRedirectTarget().title(with_ns=False)
            aliasesdict[tpage.title(with_ns=False)] = tname
            #print (tpage.title(with_ns=False), tname)
        else:
            del aliasesdict[item]
            print (item + ' not RedirectPage, DELETE!')
    else:
        del aliasesdict[item]
        print (item + ' not exists, DELETE!')
        
print('Current data checked!')
        
#aliases_order = collections.OrderedDict(sorted(aliasesdict.items(),key=lambda t:t[1]))
#jsonpage.text = json.dumps(aliases_order)
#jsonpage.save('WP aliases update')
#---------------------------
tlist = []
categorys = ['Category:含质量评级的专题横幅‎','Category:不含质量评级的专题横幅‎','Category:使用评级分类的WPBannerMeta横幅‎','Category:专题标志模板‎','Category:自定义等级的WPBannerMeta模板']
#获取所有专题模板
print('Get all banner template...')
for cat in categorys:
    catpage = pywikibot.Category(site, cat)
    for t in catpage.articles(namespaces=10):
        templatename = t.title()
        if '/' not in templatename:
            tlist.append(templatename)
            #print(templatename)
#去重
clean_tlist = list(set(tlist))

#找到专题模板的重定向页面
print('Get Redirect Page...')
for banner in clean_tlist:
    banner_page = pywikibot.Page(site, banner)
    if banner_page.exists():
        if banner_page.isRedirectPage():
            banner_page = banner_page.getRedirectTarget()
        redirects = banner_page.backlinks(filter_redirects=True)
        for r in redirects:
            #修复pywikibot API获取错误重定向页问题
            if r.getRedirectTarget()== banner_page:
                aliasesdict[r.title(with_ns=False)] = banner_page.title(with_ns=False)
                print(r.title(with_ns=False)+ ' redirect to '+ banner_page.title(with_ns=False))
#排序
aliases_order = collections.OrderedDict(sorted(aliasesdict.items(),key=lambda t:t[1]))
jsonpage.text = json.dumps(aliases_order)
jsonpage.save('WP aliases update')
#print (clean_tlist)
{{bottomLinkPreText}} {{bottomLinkText}}
User:Sz-iwbot/rater/rater.py
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?