Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 100 randomly-selected articles (weighted by popularity)  





2 Script  














User:Matt Crypto/RandomArticles

















User page
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
User contributions
User logs
View user groups
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 

< User:Matt Crypto

While Wikipedia has a Random page feature, the pages are selected uniformly randomly from the database. As an alternative, I wrote a script to choose pages randomly based on their hit counts for a month; such a set might give a more representative example of how Wikipedia looks to visitors. The hit data for, say, September 2004 can be found here (warning: very large file). Below is an example from the hits so far this month (to 22nd September 2004). If you would like a set, just send me a message and tell me a Wikipedia page, and I'll run the script for you and paste in the output. — Matt 15:06, 21 Sep 2004 (UTC)

100 randomly-selected articles (weighted by popularity)[edit]

Script[edit]

import re
from random import *

logFile = "/tmp/url_200409.html"
maxEntries = None # 10000
numberOfArticles = 100

r1 = re.compile(r'^(\d*)\s*([0-9.]*)%\s*([0-9]*)\s*([0-9.]*)%\s*/wiki/(\S*)$')

class ArticlePicker:
    def __init__(self, logFile, maxEntries = False):
        self.logFile = logFile
        self.hitList = []
        self.count = 0
        self.maxEntries = maxEntries

    def readLogFile(self):
        F = open(self.logFile)
        count = 0
        self.hitSum = 0
        for l in F:
            if self.maxEntries and count > self.maxEntries:
                break           
            try: 
                hits, name = self.parseLine(l)
            except ValueError:
                continue

            count = count + 1
            self.hitList.append((hits,name))
            self.hitSum += hits
            
        self.count = count
        F.close()
        self.hitList.sort()
        self.hitList.reverse()
        
    def parseLine(self, line):
        l = line.strip()
        
        m = r1.match(l)
        if m == None: raise ValueError, "No matches found"
        (hits, t1, t2, t3, name) = r1.match(l).groups()
        self.filterOut(hits, name)
        spaceName = re.sub('_', ' ', name)

        return int(hits), spaceName

    def filterOut(self, hits, name):
        if name == "": raise ValueError                    # Exclude blank
        if re.match(r'^\w*:', name): raise ValueError      # Exclude namespaces
        if re.match(r'Main_Page', name):  raise ValueError # Exclude main page

        # Exclude popular oddities
        if re.match(r'_vti_bin/owssvr.dl|MSOffice/cltreq.asp', name): raise ValueError


    def selectRandomly(self, N = 1):
        rHits = [random() * self.hitSum for i in range(N)]
        outputs = [None] * N
        numberOfOutputs = 0
        totalSoFar = 0
        for hits, name in self.hitList:
            totalSoFar += hits
            for index in range(N):
                if not outputs[index] and totalSoFar >= rHits[index]:
                    outputs[index] = hits, name
                    numberOfOutputs += 1
                    if numberOfOutputs == N: return outputs
        return outputs

# Dump the articles
H = ArticlePicker(logFile, maxEntries)
H.readLogFile()
randomArticles =  H.selectRandomly(numberOfArticles)
print "==%d randomly-selected articles (weighted by popularity)==" % numberOfArticles
for hits, name in randomArticles:
    print "* %s — (%d hits)" % (name, hits)

Retrieved from "https://en.wikipedia.org/w/index.php?title=User:Matt_Crypto/RandomArticles&oldid=191881419"





This page was last edited on 16 February 2008, at 17:12 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki