rcsort.py :  » Network » Python-Wikipedia-Robot-Framework » pywikipedia » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Python Wikipedia Robot Framework 
Python Wikipedia Robot Framework » pywikipedia » rcsort.py
#!/usr/bin/python
# -*- coding: utf-8  -*-
# A tool to see the recentchanges ordered by user instead of by date. This
# is meant to be run as a CGI script.
# Apart from the normal options of the recent changes page, you can add an option
# ?newbies=true which will make the bot go over recently registered users only.
# Currently only works on Dutch Wikipedia, I do intend to make it more generally
# usable.
# Permission has been asked to run this on the toolserver.
__version__ = '$Id: rcsort.py 7426 2009-10-11 08:55:37Z alexsh $'

import cgi
import cgitb
import re
cgitb.enable()

form = cgi.FieldStorage()
print "Content-Type: text/html"
print
print
print "<html>"
print "<head>"
print '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'
print '<style type="text/css" media="screen,projection">/*<![CDATA[*/ @import "http://nl.wikipedia.org/skins-1.5/monobook/main.css?59"; /*]]>*/</style>'
print "</head>"
print "<body>"
print "<!--"
import wikipedia
print "-->"
mysite = wikipedia.getSite()

newbies = 'newbies' in form

if newbies:
    path = mysite.contribs_address(self, target='newbies')
else:
    path = mysite.get_address("Special:RecentChanges")

for element in form:
    if element != 'newbies':
        path += '&%s=%s' % (element, form[element].value)
if not 'limit' in form:
    path += '&limit=1000'

text = mysite.getUrl(path)

text = text.split('\n')
rcoptions = False
lines = []
if newbies:
    Ruser = re.compile('\"Overleg gebruiker:([^\"]*)\"\>Overleg\<\/a\>\)')
else:
    Ruser = re.compile('title=\"Speciaal\:Bijdragen\/([^\"]*)\"')
Rnumber = re.compile('tabindex=\"(\d*)\"')
count = 0
for line in text:
    if rcoptions:
        if 'gesch' in line:
            try:
                user = Ruser.search(line).group(1)
            except AttributeError:
                user = None
            count += 1
            lines.append((user,count,line))
    elif 'rcoptions' in line:
        print line.replace(mysite.path() + "?title=Speciaal:RecenteWijzigingen&amp;","rcsort.py?")
        rcoptions = True
    elif newbies and 'Nieuwste' in line:
        line =  line.replace(mysite.path() + "?title=Speciaal:Bijdragen&amp;","rcsort.py?").replace("target=newbies","newbies=true")
        if '</fieldset>' in line:
            line = line[line.find('</fieldset>')+11:]
        print line
        rcoptions = True
lines.sort()
last = 0

for line in lines:
    if line[0] != last:
        print "</ul>"
        if line[0] == None:
            print "<h2>Gebruiker onbekend</h2>"
        else:
            wikipedia.output(u"<h2>%s</h2>"%line[0],toStdout=True)
        print "<ul>"
        last = line[0]
    wikipedia.output(line[2].replace('href="/w','href="http://nl.wikipedia.org/w'), toStdout = True)
    print

print "</ul>"
print "<p>&nbsp;</p>"
print "</body>"
print "</html>"
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.