[Tutor] Q&D Uselessness: crossover.py

Tesla Coil tescoil@irtc.net
Tue, 14 Aug 2001 02:03:40 -0500

Remarkably, this returned accurate results.  I don't
expect this to last, as the reduce2songs function 
is rather crocky.  Inviting modifications to make
it more reliable in view of rronline's html (and/or
improvements in any other respects).

# crossover.py -- Grabs the Top 30 "Alternative," 
# "Active Rock" and "Rock" airplay charts from
# *Radio & Records*, and compares them to see
# how alternative "Alternative Rock" is lately.

import urllib, re, sys

def reduce2songs(rawchart):
    songs = []
    for line in rawchart:
        if re.search('quot', line):
    return songs

def grabcharts():
    radiorec = 'http://www.rronline.com/chartbytes/'
    charts = ['alt.htm', 'ar.htm', 'rock.htm']
    [alt, ar, rock] = [[],[],[]]
    collected = [alt, ar, rock]
        for grab in range(3):
            collected[grab] = urllib.urlopen(radiorec+charts[grab])
            collected[grab] = collected[grab].readlines()
            collected[grab] = reduce2songs(collected[grab])
    except IOError, e:
        print e
        print "Maybe you're not connected to the internet (?)"
    return collected

def comparecharts(reduced):
    [armatch, rockmatch, allmatch] = [0,0,0]
    for line in reduced[0]:
        if line in reduced[1]:
            armatch = armatch + 1
        if line in reduced[2]:
            rockmatch = rockmatch + 1
        if line in reduced[1] and line in reduced[2]:
            allmatch = allmatch + 1
    print "*Radio & Records* currently reports that:"   
    print "Of the Top 30 songs on US Alternative radio"
    print armatch, "are Top 30 songs on US Active Rock radio,"
    print rockmatch, "are Top 30 songs on US Rock radio, and"
    print allmatch, "are Top 30 songs in all three formats."

charts = grabcharts()