Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
User Journal

Journal Journal: chk_org.pl

#!/usr/bin/perl

sub sort_color($$);

%colors = ( 'White' => 1,
                                                'Blue' => 2,
                                                'Black' => 3,
                                                'Red' => 4,
                                                'Green' => 5,
                                                'Artifact' => 6,
                                                'Land' => 7
                                    );

@array = populate_array($ARGV[0]);

@array = sort { sort_color($a, $b) } @array;

for (@array) {
                print_card($_);
}

exit;

sub sort_color($$) {
                ($card1, $card2) = @_;
                $color1 = $colors{${$card1}[0]};
                $color2 = $colors{${$card2}[0]};
                return ($color1 $color2);
                #return -1 if $color1 > $color2;
                #return 0 if $color1 == $color2;
                #return 1 if $color1 ;

                for $i (0 .. $#lines) {

                                $line = $lines[$i];

                                if( $line =~ m/^-/ ) { next; }
                                chomp($line);

                                if( $line !~ m/\(\w+ \w+\)\s*$/ ) { next; }

                                # should only have info line of any given card.

                                #$line =~ s/^\s*(.*?)\s*$/\1/g; #strip whitespace

                                substr($line, 4, 1, "|");
                                substr($line, 24, 1, "|");
                                $line =~ s/\s{4,}(\d+\/\d+)? \((\w+) (\w+)\)\s*/|\1|\2|\3/;

                                @parts = split(/\|/,$line);

                                for(@parts) {
                                                s/^\s*(.*?)\s*$/\1/g;
                                }
                                #print join("|", @parts), "\n";

                                ($cc, $name, $type, $pt, $color, $rarity) = @parts;

                                $text = "";
                                while($lines[$i+1] !~ m/^-/) {
                                                $i = $i + 1;
                                                $text .= $lines[$i];
                                }
                                chomp($text);
                                #print "$name: $text\n";

                                push(@array, [$color, $name, $cc, $type, $text, $pt, $rarity]);
                }
                return @array;
}

User Journal

Journal Journal: artgrab.py


import pullparser, sys
import urllib

def parse_scg_article(num):
    article_url = urllib("http://www.starcitygames.com/php/news/expandnews.php?"
                                                                "article="+num)
    p = pullparser.PullParser(article_url)

def parse_scg_main():
    p = pullparser.PullParser(scg_url)
    for img in p.tags("img"):
        if(dict(img.attrs).get("alt", "-") == "Strategy"):
            break

    for token in p.tags(a):
        url = dict(token.attrs).get("href", "-")
        num = token_url[-4:]
        #if token matches criteria
        parse_scg_article(num)
User Journal

Journal Journal: artsend.py

#!/usr/bin/python

from twisted.protocols import toc
from twisted.internet import reactor
from twisted.internet import base
import twisted.im.tocsupport as ts

screenname = 'SCGArticleBot'
password = 'magical'

class articleBot(toc.TOCClient):
    """AIM article transmission bot"""

    def gotConfig(self, mode, buddylist, permit, deny):
        global screenname

        # add someone to our blocked list?
        self.add_deny([])

        # add self to buddy list
        self.add_buddy([screenname])

    def updateBuddy(self, username, online, evilness, signontime, idletime, userclass, away):
        """called when a buddy changes state"""
        print "status changed for",username

    def hearWarning(self, warnlvl, screenname):
        """called when someone warns us"""
        print screenname, "warned us"

    def hearError(self, errcode, *args):
        """called when server sends error"""
        print "received error:", errcode

    def hearMessage(self, username, message, autoreply):
        """called when a message is received"""

        #remove the incoming message's html
        msg = ts.dehtml(message)
        print "got message:",msg
        reply = ts.html("echo: %s" % msg)

        self.say(username, reply)

    def onLine(self):
        """called when we first sign online"""
        print "Signed online"

bot = base.BCFactory(aimBot(screenname, password))
reactor.connectTCP("toc.oscar.aol.com", 9898, bot)

reactor.run()

Slashdot Top Deals

Refreshed by a brief blackout, I got to my feet and went next door. -- Martin Amis, _Money_

Working...