Catch up on stories from the past week (and beyond) at the Slashdot story archive


Forgot your password?
DEAL: For $25 - Add A Second Phone Number To Your Smartphone for life! Use promo code SLASHDOT25. Also, Slashdot's Facebook page has a chat bot now. Message it for stories and more. Check out the new SourceForge HTML5 internet speed test! ×
User Journal

Journal Journal:


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) {


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; }

                                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) {
                                #print join("|", @parts), "\n";

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

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

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

User Journal

Journal Journal:

import pullparser, sys
import urllib

def parse_scg_article(num):
    article_url = urllib(""
    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"):

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

Journal Journal:


from twisted.protocols import toc
from twisted.internet import reactor
from twisted.internet import base
import 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?

        # add self to buddy list

    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("", 9898, bot)

Slashdot Top Deals

In a consumer society there are inevitably two kinds of slaves: the prisoners of addiction and the prisoners of envy.