Ejemplo n.º 1
0
    def get(self):
        try:
            year = int(self.request.get('year'))
            month = int(self.request.get('month'))
            day = int(self.request.get('day'))
            datetime(year, month, day)  # Validation
            gid = self.request.get('gameID')
        except (TypeError, ValueError):
            self.abort(400)

        url = ('http://gd2.mlb.com/components/game/mlb/year_%04d/month_%02d/'
               'day_%02d/%s') % (year, month, day, gid)

        self.response.headers['Content-Type'] = 'image/svg+xml'

        # Figure out which teams are playing.  MLB uses inconsistent codes
        # to represent teams (i.e. nya & nyy for the Yanks) so translate
        # from the code in the gid to the code for the logo PNG
        away_code = LOGOS.get(gid.split('_')[4][:3], None)
        home_code = LOGOS.get(gid.split('_')[5][:3], None)
        box = BoxScore(away_code, home_code, self.response.out)

        # Create a parser
        parser = make_parser()
        # Tell the parser we are not interested in XML namespaces
        parser.setFeature(feature_namespaces, 0)

        p = procMLB(box, url)

        parser.setContentHandler(p)

        # Read the inning directory and process each inning
        s = urlopen(url + '/inning/').read()

        for i in range(1, len(re.findall('"inning_\d+\.xml"', s)) + 1):
            parser.parse(urlopen(url + '/inning/inning_' + str(i) + '.xml'))
            if i == len(re.findall('"inning_\d+\.xml"', s)):
                box.endInning(gameOver=True)
            else:
                box.endInning()
        box.endBox(p.homePitchers, p.awayPitchers, p.away_score, p.home_score)
Ejemplo n.º 2
0
    f = urlopen(url)
    DATA = f.read()
    f.close()

    for game in re.findall('href="(gid.*?)"', DATA):
        if game.find(TEAM + "mlb") > 0:
            url += game
            break

    IMG = open("test.svg", "w")
    BOX = BoxScore(IMG)

    PARSER = make_parser()
    PARSER.setFeature(feature_namespaces, 0)
    p = procMLB(BOX, url)
    p.offline = True
    PARSER.setContentHandler(p)

    f = urlopen(url + '/inning')
    s = f.read()
    f.close()
    for i in range(1, len(re.findall('"inning_\d+\.xml"', s)) + 1):
        print 'Inning: ' + str(i)
        f = urlopen(url + '/inning/inning_' + str(i) + '.xml')
        PARSER.parse(f)
        f.close()
        if i == len(re.findall('"inning_\d+\.xml"', s)):
            BOX.endInning(gameOver=True)
        else:
            BOX.endInning()
Ejemplo n.º 3
0
if __name__ == '__main__':
    if (len(sys.argv) != 2):
        print "USAGE: ", sys.argv[0], " <GAMEURL>"
        sys.exit(1)

    url = sys.argv[1]
    img = open("box.svg", "w")
    box = BoxScore(img)
    box.startBox()

    # Create a parser
    parser = make_parser()
    # Tell the parser we are not interested in XML namespaces
    parser.setFeature(feature_namespaces, 0)

    p = procMLB(box, url)

    parser.setContentHandler(p)

    # Read the inning directory and process each inning
    f = urlopen(url + '/inning')
    s = f.read()
    f.close()
    for i in range(1, len(re.findall('"inning_\d+\.xml"', s)) + 1):
        f = urlopen(url + '/inning/inning_' + str(i) + '.xml')
        parser.parse(f)
        f.close()
        box.endInning()
    box.endBox()
    img.close()