[Pywikipedia-l] SVN: [4832] trunk/pywikipedia/featuredcount.py

leogregianin at svn.wikimedia.org leogregianin at svn.wikimedia.org
Wed Jan 9 16:33:37 UTC 2008


Revision: 4832
Author:   leogregianin
Date:     2008-01-09 16:33:36 +0000 (Wed, 09 Jan 2008)

Log Message:
-----------
This script only counts how many have featured articles in all wikipedias

Added Paths:
-----------
    trunk/pywikipedia/featuredcount.py

Added: trunk/pywikipedia/featuredcount.py
===================================================================
--- trunk/pywikipedia/featuredcount.py	                        (rev 0)
+++ trunk/pywikipedia/featuredcount.py	2008-01-09 16:33:36 UTC (rev 4832)
@@ -0,0 +1,60 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+"""
+This script only counts how many have featured articles all wikipedias.
+
+usage: featuredcount.py
+
+"""
+__version__ = '$Id: featured.py 4811 2008-01-05 16:22:45Z leogregianin $'
+
+#
+# Distributed under the terms of the MIT license.
+#
+
+import sys
+import wikipedia, catlib
+from featured import featured_name
+
+def CAT(site,name):
+    cat=catlib.Category(site, name)
+    return cat.articles()
+
+def BACK(site,name):
+    p=wikipedia.Page(site, name)
+    return [page for page in p.getReferences(follow_redirects = False)]
+
+def LINKS(site,name, ignore=[]):
+    p=wikipedia.Page(site, name)
+    links=p.linkedPages()
+    for n in links[:]:
+        t=n.titleWithoutNamespace()
+        if t[0] in u"/#" or t in ignore:
+            links.remove(n)
+    links.sort()
+    return links
+
+def featuredArticles(site):
+    method=featured_name[site.lang][0]
+    name=featured_name[site.lang][1]
+    args=featured_name[site.lang][2:]
+    raw=method(site, name, *args)
+    arts=[]
+    for p in raw:
+        if p.namespace()==0:
+            arts.append(p)
+        elif p.namespace()==1:
+            arts.append(wikipedia.Page(p.site(), p.titleWithoutNamespace()))
+    wikipedia.output('\03{lightred}** wikipedia:%s has %i featured articles\03{default}' % (site.lang, len(arts)))
+    return arts
+
+if __name__=="__main__":
+    fromlang=featured_name.keys()
+    fromlang.sort()
+    try:
+        for ll in fromlang:
+            fromsite=wikipedia.Site(ll)
+            if not fromsite==wikipedia.getSite():
+                arts=featuredArticles(fromsite)
+    finally:
+        wikipedia.stopme()





More information about the Pywikipedia-l mailing list